Omar wrote:
Hi,
Is it possible to set to a hidden element the value of an item
selected in a dropdown menu using a JavaScript funtion or something??
I appreciate your help.
Yes, that was in my first post. Somehow the submit button went
missing, below is a version with a submit button.
The reason I suggested doing it on submit is because that is the only
time you can guarantee that you can make the two the same. The only
other event that makes any sense is using onchange, but I don't
recommend that for the reasons given.
Actually, some of the behaviours don't happen in version 1.03 of
Firefox - I just updated and the reset thing now works as per IE and
navigation keeps the selection and value. Re-loading the page does
not change either value. But I think the behaviour across all
browsers still warrants some extra precautions.
If you want to try it, move/copy the onsubmit code to an onchange on
the select...
<select name="nombre" onchange="
this.form.valorPos.value = this.value;
">
You could create a listener that is started by onchange and looks at
the value of the select every 50 milliseconds or so and makes the
values the same, but I can't see the point in doing it when onsubmit
will do a better job, without hogging CPU and without the 1-in-1000
chance (or maybe it's higher, I dunno) that the user changes their
selection and submits the form before the listener updates the value.
So you'd add an onsubmit anyway...
<form action="" onsubmit="
this.valorPos.value = this.nombre.value;
">
<select name="nombre">
<option value="default" selected>Select an option</option>
<option value="valorColumna0">Option 0</option>
<option value="valorColumna1">Option 1</option>
</select><br>
<input type="hidden" name="valorPos" value="default">
<input type="button" value="Show valorPos value" onclick="
alert(this.form.valorPos.value);
">
<input type="reset" onclick="
this.form.valorPos.value='default';
">
<input type="submit" value="Send data...">
</form>
--
Fred