Share via E-Mail
Share on Google Buzz
Share on Twitter
Share on Facebook
E-junkie Blog
E-junkie FaceBook Page
E-junkie @ Twitter

E-junkie Ecommerce Forums » E-junkie Discussions

Tag Cloud for this topic:

Solution: Apply Coupon Code via Input Box



SimpleRain
member
Posts: 1


Hey all, I programmed this for a client, so I thought I would share it with the community. This is how you can apply a coupon via an input field and button rather than in the cart. This is useful when you want to change the text for the coupon box.

You can see a working demo here: http://simplerain.com/e-junkie/

Here is the simple function:


---------------------------------------------------------------------- -----------------------------------
<script language="javascript" type="text/javascript">
<!--
function addcode(note){
var userInput = document.getElementById('userInput').value;
document.url.action = document.url.action+'&discount_code='+userInput;
document.getElementById('userInput').value = 'enter it here';
return EJEJC_lc(note);
}
function EJEJC_lc(th) { return false; }
document.write("<scr"+"ipt src='" + document.location.protocol + "//www.e-junkie.com/ecom/box.js' type='text/javascript'></scr"+"ipt>");
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = stopRKey;
// -->
</script>

<form name="url" action="https://www.e-junkie.com/ecom/gb.php?c=cart&cl=38825&ejc=2" target="ej_ejc" method="POST" accept-charset="UTF-8">
<input type="text" id="userInput" class="urlinput" value="enter it here" onfocus="if (this.value == 'enter it here') { this.value=''; }" onblur="if (this.value == '') { this.value='enter it here'; }" />
<input type="button" class="submitbutton" onclick="addcode(this.parentNode)" style="width: auto;" value="Apply Coupon" />
</form>
---------------------------------------------------------------------- -----------------------------------


The only thing you will need to change is this line:
<form name="url" action="https://www.e-junkie.com/ecom/gb.php?c=cart&cl=38825&ejc=2" target="ej_ejc" method="POST" accept-charset="UTF-8">

You need the action url to match the URL found in your view cart button.

For this to function I also had to disable the return key for the page otherwise a new window opened up if anyone hit enter on the input box. This function should just be plug and play for anyone who wants it. Hope it helps someone out since it's an option e-junkie should just provide as default, as it was a desire for my client. So they paid for it, and the community benefits. Just gives props to my company if you feel like it, otherwise enjoy.

-Dovy Paukstys
SimpleRain Studios
http://simplerain.com/


#
POSTED ON: October 23, 2008 @ 21:14 GMT -7
MODIFIED ON: October 23, 2008 @ 21:24 GMT -7




E-junkieChef
E-Junkie Crew
Posts: 936


Dovy, I love the way you've customized our solution .. will you be interested in getting listed in our developer directory?


#
POSTED ON: October 28, 2008 @ 12:42 GMT -7


You must be logged in to make a post. Please click here to login.

30 Day Money Back Guarantee
PayPal Certified Integration
Google Checkout Certified Integration
Slam the Online Scam