Reputation: 297
i am trying to submit values of form.
but all values other than a <select>
field is not submitted because i think its inside div element as shown in code below
<form action="next.php" method="post">
<input>....
<input>....
<input>....
<select name="asdf"> <!--This field submitted successfully -->
<option value="wtevr"> </option>
<option value="wtevr2"> </option>..........
</select>
<div>
<select name="asdf2"> <!--problem is here submitting this field -->
<option value="wtevr11"> </option>
<option value="wtevr22"> </option>..........
</select>
</div>
</form>
I used div
because this is part of my ajax code through which i update the values in select field.
Is there any alternative solution to submit this select
field form?
MY approach:
I think that there is a solution if i use a hidden
input
field in this form whose value get equal to value of select field before submitted the form.
<input type="hidden" value="<!--comes from JavaScript code -->">
I am new to JavaScript so any help is appreciated..
Upvotes: 4
Views: 3458
Reputation: 564
The <select>
tag has a property called [form=""].
With that you can assign it to a form element.
As the form gets submitted, the select element is included.
<form name="myform">
<input type="text" name =...>
<select name="selectelement" form="myform">
<input type="submit">
</form>
Upvotes: 0
Reputation: 4669
You could use:
<select name="asdf2" id="asdf2" onchange="setField();">
<option value="this">this</option>
<option value="that">that</option>
</select>
<input type="hidden" id="hiddenField" value="nothingYet">
<script type="text/JavaScript" language="JavaScript">
function setField() {
toWhat = document.getElementById("asdf2").value
document.getElementById("hiddenField").value = toWhat;
}
</script>
In any case. If all you're doing is submitting the form, there really is no reason for that value to be ignored. How are you retrieving the values?
Upvotes: 1
Reputation: 1
Use a 'name' tag in your inputs, then they'll be submitted. like this:
<form action="next.php" method="post">
<input name="foo" value="var"/>
</form>
Upvotes: 0