Change hidden field value when dropdown list changes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MOzgaf
    New Member
    • Dec 2010
    • 13

    Change hidden field value when dropdown list changes

    Hi,

    The problem is I have a list that i want to send to other file(php) but I want to send two corresponding variables. I was wondering if this is easy with the hidden field.

    Code:
    <select id='myselect'>
        <option value='1'>A</option>
        <option value='2'>B</option>
        <option value='3'>C</option>
        <option value='4'>D</option>
    </select>
    <input type='hidden' id='myhidden' value=''>
    If I want to select A I want the hidden value to change to email address corresponding with A. I dont want to use 1 ,as 1 is the name of person and that is used to look for him in the php file.

    The Questions, is there an eisier way that using IF and ELSE statements? because the list is very long.
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    Code:
    <select id='myselect' onchange="document.getElementById('myhidden').value=this.value">
        <option value='1'>A</option>
        <option value='2'>B</option>
        <option value='3'>C</option>
        <option value='4'>D</option>
    </select>
    <input type='hidden' id='myhidden' value=''>

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      if you want to do a form submit (i.e. not AJAX) you would have to give the form elements a name.

      Comment

      Working...