Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onSelect assign value to hidden input

Status
Not open for further replies.

alsaffar

Programmer
Oct 25, 2001
165
KW
Hi there,

I have a hidden input called (amount)

<input type='hidden' name='amount'>

and I have a select input called (amount_desc)

<select name='amount_desc'>
<option value='1'>1</option>
<option value='2'>2</option>
</select>

My aim is when an option of the select input is selected to set its value to the hidden input

So when the form is submitted, the hidden input have the selected option in the select input

Thanks in advance ;)
 
I forgot to mention is that each input (amount) and (amount_desc) are in different form in the same page
 
Code:
<script type="text/javascript">
<!--//
function fillHidden(select) {
    document.this_form.amount.value = select;
}
//-->
</script>

<form name="this_form">

<select name="amount_desc" onChange="fillHidden(this.value)">
  <option value="1">1</option>
  <option value="2">2</option>
</select>

<input type="hidden" name="amount">
</form>

M. Brooks
 
Once again!
Code:
<script type="text/javascript">
<!--//
function fillHidden(select) {
    document.this_form2.amount.value = select;
}
//-->
</script>

<form name="this_form1">

<select name="amount_desc" onChange="fillHidden(this.value)">
  <option value="1">1</option>
  <option value="2">2</option>
</select>

<form name="this_form2">
<input type="hidden" name="amount">
</form>

M. Brooks
 
mbrooks, I love your fast response ('',)

one more question,

lets say that the hidden input in a form without a name

and I can't put a name for it

and the select input in different form

can I still change the value of the hidden input based on the selection of the select input?

Thanks in advance ;)
 
How it can be a hack if both forms in the same page!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top