A user selects in two select-lists number of rows and cols to setup a grid, let's say 2x3. In a third select-list the user can only select a maximum of 6, not more.
The max of 6 depends on choice before 2x3. I don't get the value of 6 into the selectpicker's data-max-options attribute. Is this even possible to update this attribute depending on two other inputs?
Using snapappointments's bootstrap-select from Github would be fine. But fallback to plain jquery is ok to get it run. Maybe data-max-options attribute isn't to be updated during script run, have read this in other questions but unfortunately I'm not that much experienced with that so any hint highly appreciated.
<select class="grid rows">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<select class="grid cols">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input type="text" id="max" title="just demo" />
<select id="grid" size="10" multiple="multiple" class="selectpicker show-tick" data-max-options="2">
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
</select>
<script type="text/javascript">
$(".grid").change(function (event) {
var rows = $(".grid.rows option:selected").val();
var cols = $(".grid.cols option:selected").val();
var grid = rows * cols;
if (grid == 0) {
$('#max').val('');
} else {
$('#max').val(grid);
}
console.log("number" + grid);
});
// $('#grid').data('max-options', 6); // this works, but not inside above function
</script>