...

View Full Version : passing variable to javascript and using as command



jtnz
10-22-2003, 09:45 AM
I'm trying to pass a variable created in ASP to a javascript function so that i can use it as a command, if i output the string i pass, it looks fine, but javascript just treats it as text :(

any suggestions Gratefully recieved

James

The Generated Code that passes the variable:

<select name='PPEventQTYG' onchange='UpdatePPEventTotal("orderForm.PPEventQTYG.value")' >
<option value ='0'>0</option>
<option value ='1'>1</option>
<option value ='2'>2</option>
</select>

The Javascript Function

function UpdatePPEventTotal(Qty){
orderForm.PPEventTotal.value = Qty;
}

glenngv
10-22-2003, 10:49 AM
It's treated as text because you had quotes in it.
You should remove it.

<select name="PPEventQTYG" onchange="UpdatePPEventTotal(this.form.PPEventQTYG.value)" >

you can also use:

UpdatePPEventTotal(document.orderForm.PPEventQTYG.value)

but using this.form is better since you don't have to know what the form name is.

jtnz
10-22-2003, 11:00 AM
Thanks Glenn

Worked a treat

Obvious really - newbie screw up!!

James



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum