Link to home
Start Free TrialLog in
Avatar of kustiel
kustiel

asked on

change the price (which is a form 'read only' element) when a coupon code is entered

Hi, I have a checkout form, that you can see at the end of the shopping process starting from: http://www.paintyourlife.com/shop.asp

At the checkout page, I would like to allow the customers to enter a coupon code which will update the price of their order.

I already do it using a checkbox of 'express service' to which I add onClick="calculatePrice(this)"

but with the coupon code it's different. Is there any event type I can use?  
If not, then I need to add an "update" button near the coupon code input field, but that means a form inside another form (which as far as I know is not allowed)

Any suggestions?

*Any remarks regarding the whole shopping process will be appreciated.

Thanks a lot,

Assaf
Avatar of Jason Minton
Jason Minton
Flag of United States of America image

I would use either onChange or onBlur.

onChange will fire your function as soon as you type something into the box... So, what you'd want to do for this method is have your function check for a valid code and if it's valid update your price.

or

onBlur will fire your function when the user tabs or click out of the box (opposite of onFocus basically), so after they enter a code and then tab or click elsewhere it will fire the function and update the price.

Avatar of kustiel
kustiel

ASKER

Hi,

Thanks for the prompt answer.
Now, when I do the onBlur, I get to a JavaScript functiion, in which I need to check in my SQL database, whether such a coupon code exist, and what discount is associated with it.
My question is: how do I access the database from within the JavaScript code. Until now, I only did it from my ASP/VBSCRIPT code.

Thanks, Assaf
ASKER CERTIFIED SOLUTION
Avatar of Jason Minton
Jason Minton
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kustiel

ASKER

Hi jasonsbytes,

I'm trying to implement your solution and I;m still a bit confused....

There are 2 things I need to do:

1.) Store the values in the array - to do this, I need to call a JavaScript function in the OnLoad of the body tag, right? Then, from inside this function I call the SQL database to read the values? I have never accessed the SQL DB from inside a JavaScript function. I always did it in the ASP / VSCRIPT code. Is it the same?

2.) Laster, when someone will enter a coupon code, I will call some OnBlur function. Will this function be able to use the variable I used in the former function? Are these global variables?

I'm sorry if my questions sound strange. I just come from a world of c, c++ coding and am pretty new to this web developing.

Thanks, Assaf