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!

updating a hidden field from a select box

Status
Not open for further replies.

skobo

Programmer
Jul 27, 2001
4
US
I've got a select box that I need to pass both numeric value and the text label of the option the user selects. I set up a hidden field for the text label. With my very limited JavaScript knowledge I have been unable to figure out how to get an OnChange event to update the hidden field.

Any help would be appreciated.

Thanks,
Chris
 
here i think this is what youre looking for:
Code:
<html>
<head>
<Script language='javascript'><!--
function changeHidden(text)
{
document.forms[0].hiddenField.value = text;
}
//--></script>
</head>
<body><form>
<select name='select1' onChange='changeHidden(this.options[this.selectedIndex].text)'>
<option>option1</option>
<option>option2</option>
<option>option3</option>
<option>option4</option>
</select>
<input type='text' name='hiddenField'>
</form>
</body>
</html>

hope it helps -- if you have any questions, just ask. &quot;Those who dare to fail miserably can achieve greatly.&quot; - Robert F. Kennedy
So true..
 
This will move your select option's value to the box. I don't think that you can get the description (never tried). This may need to be changed for NetScape (which I can do if you need)


<form name=myForm>
<input name=holder>
<select onchange=&quot;document.myForm.holder.value=this.value&quot;>
<option value=1>1
<option value=2>2
<option value=3>3
</select>
</form> -----------------------------------------------------------------
DIM bulb
SET bulb = NEW brain

mikewolf@tst-us.com
 
I am trying to do something similar, using a pop up. I'm dynamically creating the list to be displayed in the pop up and want to return the code selected and the text description. Did you get it to work?

Holly
 
here's one way to do it - note that the &quot;hidden&quot; field is not &quot;type=hidden&quot; for the purpose of demonstration:

[tt]
<html>
<head>
<title></title>

<script language=&quot;javascript&quot;>
function doChange(oEl) {
var h = document.forms[0].hidden;
if (oEl.selectedIndex == 0) h.value = &quot;&quot;;
else h.value = oEl.options[oEl.selectedIndex].value + &quot;-&quot; + oEl.options[oEl.selectedIndex].text;
}
</script>

</head>

<body onLoad=&quot;&quot;>
<form>
<select name=&quot;&quot; onchange=&quot;doChange(this);&quot;>
<option value=&quot;&quot;>Choose:</option>
<option value=&quot;1&quot;>one</option>
<option value=&quot;2&quot;>two</option>
<option value=&quot;3&quot;>three</option>
</select>
<p/>
<input type=&quot;text&quot; name=&quot;hidden&quot; />
</form>
</body>
</html>

[/tt]
=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top