Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript function

Status
Not open for further replies.

funkyspirit

Programmer
Oct 6, 2011
12
GB
Hi there,

I am having an issue with a function and I can't get my head round it.

I have an asp/VBScript page our customers use to enter their data after choosing the product they want to buy, which displays the price of the package they chose.

I would like to enable them to enter a voucher code by selecting the code from a drop-down list and have the price recalculated according to the voucher code selected.

I was thinking of creating an onchange event on the drop-down list, which would pass the voucher code and the normal price to a JavaScript function to recalculate the price.

My problem is that the normal price is calculated by calling a VBScript function, named CalcPrice. CalcPrice takes two arguments, which are obtained from the previous page by using a Request() statement, as shown below:

CostPac = CalcPrice( Request("Pack"), Request("voucher"))

My question is how could I use the CostPac as a parameter alongside the voucher code when I call the JavaScript function to calculate the new price, in the onchange event of the drop down list.

The code I have tried for the drop-down list is below:

<div class="fieldbottommargin"></div>
<br />
<select class="SelectFields_voucher"onchange="calculateDiscount(this.options[selectedIndex].value,<%=CalcPrice( Request("Pack"),Request("voucher"))">
<option value="vch010">vch010</option>
</select>

But that, as I thought, does not work.

I hope this makes sense.

Any help would be greatly appreciated.

Thanks.
 
1.) you need to save the values, so that you can use them as the basis for your calculations later. Hidden fields or Javascript values

2.) somewhere you will have to have a correlation between offer code & markdown/$ off. You can do this with 2 arrays

3.) Remember Javascript is executed top to bottom, so you can put "random" inline in if you need something to happen between 2 things being set (this is icky, but an option)

4.) Need more code than that to figure out what you need to do. BTW, where is the close bracket for the <%=CalcPrice?

Good Luck.

You've got questions and source code. We want both!
 
Another option might be to use AJAX. Stuff Request("Pack") and Request("voucher") in variables (session?) and have the onChange pass those (or whatever you need) to your existing backside VBScript function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top