And enter Html select in another select but the second select does not send information either by GET or by POST. I don’t know where I will add the id = “” and name = “” in JavaScript, to make it work.
JavaScript
x
<select id="type" name="type">
<option value="item1">item1</option>
<option value="item2">item2</option>
<option value="item3">item3</option>
</select>
<select id="size">
<option value="">-- select one -- </option>
</select>
<script>
$(document).ready(function() {
$("#type").change(function() {
var val = $(this).val();
if (val == "item1") {
$("#size").html("<option value='test'>item1: test 1</option><option value='test2'>item1: test 2</option>");
} else if (val == "item2") {
$("#size").html("<option value='test'>item2: test 1</option><option value='test2'>item2: test 2</option>");
} else if (val == "item3") {
$("#size").html("<option value='test'>item3: test 1</option><option value='test2'>item3: test 2</option>");
}
});
});
</script>
With type it works, but it receives only the information of the first select
It is included in form. And the source code is this: http://jsfiddle.net/YPsqQ/
Advertisement
Answer
By “it works” I assume you mean these elements are part of a <form>
which is being submitted at some later point? The first <select>
sends its value in that form because it has a name
:
JavaScript
<select id="type" name="type">
The second <select>
is missing its name
, so a <form>
has no way to include it. Simply give it a name
:
JavaScript
<select id="size" name="size">