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="ejejc" 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="ejejc" 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/