Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    passing variable to javascript and using as command

    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;
    }

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Glenn

    Worked a treat

    Obvious really - newbie screw up!!

    James


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •