Reputation: 21025
I have a form:
<form class="form-horizontal" role="form"
action="/createstudent" method="POST">
<div class="form-group">
<label for="fieldName" class="col-sm-2 control-label">First name:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="fieldName" name="firstname">
</div>
</div>
//....more input fields....
<div class="form-group">
<label for="classof">Class of:</label>
<select class="form-control" id="classof">
</select>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<button type="submit" class="btn btn-default">Create</button>
</div>
</div>
</form>
<script>
$(document).ready(function(){
var $select = $("#classof");
var currentTime = new Date();
var year = currentTime.getFullYear();
for (var i=0;i<13;i++) {
$select.append('<option value=' + (year + i) + '>' + (year + i) + '</option>');
}
});
</script>
As you can see, the options for the select input field, are populated dynamically, when the page loads. When I post my form (by clicking on the button), the request body contains the details of all the other fields (first name etc.), but there are no details of the select object... Why isn't it in the request body ?
Upvotes: 0
Views: 66
Reputation: 1536
Name attribute is missing here
<div class="form-group">
<label for="classof">Class of:</label>
<select class="form-control" id="classof" name="selected_item">
</select>
</div>
Upvotes: 1