I have few select dropdown working nicely with selectize.js. On form post, it appears it only send the last option selected. So for example, if the user select's: A, B, C in the form post var_dump($_POST); only C appears. Same is the case with other select.
I went through the documentation and searched online but not able to rectify, I am sure its something really trivial but till I know, I don't know :(
Would greatly appreciate any help! Thank you!
Let's see 6 different ways of changing the selected option using JavaScript: 1. Changing selected option by value In order to change the selected option by the value attribute, all we have to do is change the value property of the <select> element. The select box will then update itself to reflect the state of this property.
If multiple items can be selected with a "select" input tag (e.g. <select multiple> ), this returns an array. Otherwise, returns a string (separated by delimiter if "multiple"). Resets the selected items to the given value.
It can be the text that gets displayed on the option element, its index, its id etc. Let's see 6 different ways of changing the selected option using JavaScript: 1. Changing selected option by value
Selectize.js Selectize is the hybrid of a textbox and <select> box. It's jQuery-based and it's useful for tagging, contact lists, country selectors, and so on.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="http://brianreavis.github.io/selectize.js/js/selectize.js"></script>
<?php
if(isset($_POST["save"])){
echo '<pre>';
print_r($_POST);
echo '</pre>';
}
?>
<form action="" method="post">
<label>Select Class(s)</label>
<select multiple id="classname" name="classname[]" required class="form-control">
<option value="1">NUR</option>
<option value="2">KG</option>
<option value="3">PREP</option>
<option value="4">I</option>
<option value="5">II</option>
</select>
<label>Subjects</label>
<select multiple id="subjects" name="subjects[]" required class="form-control">
<option value="1">English</option>
<option value="2">EVS</option>
<option value="3">Maths</option>
<option value="4">Science</option>
<option value="5">Social</option>
</select>
<label>Examinations</label>
<select multiple="multiple" id="exams" name="exams[]" required="true" class="form-control">
<option value="1">Formative Assessment I</option>
<option value="2">Formative Assessment II</option>
<option value="3">Formative Assessment III</option>
<option value="4">Formative Assessment IV</option>
<option value="5">Annual</option>
</select>
<input type="submit" name="save" value="save" />
</form>
<script>
$(document).ready(function () {
$('#exams').selectize({
hideSelected: 'true'
});
$('#subjects').selectize({
hideSelected: 'true'
});
$('#classname').selectize({
hideSelected: 'true'
});
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With