cm*******@yahoo.co.uk wrote:
I have a form that has a select list.
A user chooses a value and the page refreshes showing the selected
value in the dropdown box.
So I want to use Javascript to get the selected query from the form.
I then want to pass it as a hidden field.
So for example the section of the page I'm interested in will look like
this.
<form action="asubmitpage.htm" method="post">
<select name="ent" onchange="form.submit();">
<option value="UK">UK</option>
<option selected value="USA">USA</option>
<option value="JAPAN">JAPAN</option>
<option value="UK">UK</option>
</select>
I then want to take the selected value and submit it as a hidden field.
<form action="setpov.htm" method="post">
<input type="hidden" name="Entity" value=" this is where i want to fill
this with the selected value ">
</form>
I take it javascript is the easiest way to do this.
Your explanation is very confusing. As far as I can tell, you have two
forms. When an option is selected in one form, you want that form to
submit, then re-load the same page with the selected option as the
default selected.
e.g. if I selected "JAPAN", the form submits and the page loads with
"JAPAN" as the default selected, not "USA".
When the page loads, you want to copy the value of the selected option
to a hidden field in another form. Is that it? Seems unusual, but
you're obviously keen to do it.
The obvious solutions are:
1. Have one form and submit it all in one go, no need for the onchange
submit.
2. When the first form submits, return the selected value in the hidden
field. You say this isn't an option, yet you must be going to
change the default selected option anyway.
Given neither of the above seems appropriate:
3. Have the second form get the value of the selected option when it
submits. Then the first doesn't need to submit at all (submitting
onchange is nasty at any time - the user has to repost the form if
they make a simple slip-up).
4. Have an onload function that gets the value of the selected option
and puts it into the hidden field in the second form.
--
Rob