By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,527 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,527 IT Pros & Developers. It's quick & easy.

Change hidden field value when dropdown list changes

P: 13
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.

Expand|Select|Wrap|Line Numbers
  1. <select id='myselect'>
  2.     <option value='1'>A</option>
  3.     <option value='2'>B</option>
  4.     <option value='3'>C</option>
  5.     <option value='4'>D</option>
  6. </select>
  7. <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.
Dec 20 '11 #1

✓ answered by johny10151981

Expand|Select|Wrap|Line Numbers
  1. <select id='myselect' onchange="document.getElementById('myhidden').value=this.value">
  2.     <option value='1'>A</option>
  3.     <option value='2'>B</option>
  4.     <option value='3'>C</option>
  5.     <option value='4'>D</option>
  6. </select>
  7. <input type='hidden' id='myhidden' value=''>
  8.  

Share this Question
Share on Google+
2 Replies


100+
P: 1,059
Expand|Select|Wrap|Line Numbers
  1. <select id='myselect' onchange="document.getElementById('myhidden').value=this.value">
  2.     <option value='1'>A</option>
  3.     <option value='2'>B</option>
  4.     <option value='3'>C</option>
  5.     <option value='4'>D</option>
  6. </select>
  7. <input type='hidden' id='myhidden' value=''>
  8.  
Dec 21 '11 #2

Dormilich
Expert Mod 5K+
P: 8,639
if you want to do a form submit (i.e. not AJAX) you would have to give the form elements a name.
Dec 21 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.