#1
  1. I am still learning
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Kuala Lumpur, Malaysia
    Posts
    249
    Rep Power
    12

    variable variable in JavaScript


    How can I possible do a variable variable thingy in JavaScript. I am too used to PHP's variable variable and I am wondering if JavaScript have such feature.

    Scenerio would be:

    Code:
    <script language="JavaScript">
      
      function doTest(test){
            thisVar = "form_var_"+test;
            document.form.thisVar.value='YAY!'
      }
    
    </script>
    
    <form name="myForm">
    <input type="button" value="button 1" onClick="doTest('one')">
    <input type="button" value="button 2" onClick="doTest('two')">
    
    <input type="text" value="hello world" name="form_var_one">
    <input type="text" value="hello mum" name="form_var_two">
    </form>

    Feedback will be much appreciated. Thanks.
    I have yet to find the right way to do it.

    www.genedavinci.com
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Code:
    document.myForm[thisVar].value='YAY!'
    -james
  4. #3
  5. I am still learning
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Kuala Lumpur, Malaysia
    Posts
    249
    Rep Power
    12
    perfect!!!... cheers!
    I have yet to find the right way to do it.

    www.genedavinci.com

IMN logo majestic logo threadwatch logo seochat tools logo