Assigning a value to Hidden Type.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thanawala27
    New Member
    • Mar 2007
    • 68

    #1

    Assigning a value to Hidden Type.

    Hi, I am a beginner here.

    I was not knowing how to assign the value of a Dropdown menu to a Hidden type variable.

    Code:
    ------------------------------------------------------------------------------------
    [CODE=html]<form name=form1 onsubmit="test( )">

    <select name=car>
    <option value ="volvo">Vol vo</option>
    <option value ="saab">Saab </option>
    <option value ="opel">Opel </option>
    <option value ="audi">Audi </option>
    </select>

    <input type=hidden name=hidden_car value="******** **">

    <INPUT TYPE=SUBMIT VALUE=ENTER>[/CODE]

    --------------------------------------------------------------------------------------

    now, i want the hidden variable 'hidden_car" TO have the value that is selected from the dropdown menu before the SUBMIT button is hit.
    in the above example, im not sure what shud be entered in place of ******** for the hidden variable.


    Any help is appreciated.

    Thank You
    Last edited by gits; Oct 15 '07, 07:12 AM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    please use CODE tags when posting source-code ...

    to your problem: you may use the onchange-event of the select-element to invoke a function that sets its current value to the value of the hidden field, here is an example (snippet):

    [CODE=html]function set_value(obj) {
    // give your hidden field an id, so that we may retrieve it here
    var hidden_field = document.getEle mentById('my_hi dden_field');

    hidden_field.va lue = obj.value;
    }

    <select name="car" onchange="set_v alue(this);">[/CODE]
    give this a try and post back in case you encounter problems with it. note that you should assign a default value to the field ... since the function is invoked onchange ... that means only when another option than the current option will be selected ...

    kind regards

    ps: please enclose html-nodes attribute values in double-quotes in your code!

    Comment

    Working...