Newbie needs help! Passing select values to hidden text field...

M

Matt

I know there have to be a million tutorials on this, but I can't seem to
find any of them. Using onsubmit, how do I pass the value from a select
menu to a hidden text field? Any help would be greatly appreciated.
 
I

Ivo

I know there have to be a million tutorials on this, but I can't seem to
find any of them. Using onsubmit, how do I pass the value from a select
menu to a hidden text field? Any help would be greatly appreciated.

Are you sure you don't want to do this in the serverside script? That is
always more reliable as users may have no javascript. Anyway, one of a
million possible approaches:

<script type="text/javascript">
function seltohid(el){
var sel=el.elements['sel'];
el.elements['hid'].value=sel[sel.selectedIndex].value;
return true;
}
</script>
</head>
<body>
<form name="f" onsubmit="return seltohid(this)">
<input type="hidden" name="hid" value="">
<select name="sel">
<option value="jack">jack
<option value="john">john
<option value="mary">mary
</select>
<input type="submit">
</form>

HTH
Ivo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top