I have two select dropdown. Example:If i select index 3 in the first select option,the display of the 2nd select option should stop at index 3.What is the best way of doing it.See my current code below.
<label class="control-label">SY1:</label>
<select class="form-control" name="pri_sy" id="pri_sy" onchange="">
<?php
$null = 'Null';
$choose = 'Choose School Year';
$Present = 'Present';
echo '<option value='.$null.'>' .$choose.'</option>';
echo '<option value='.$Present.'>' .$Present.'</option>';
for($i=date('Y'); $i > date('Y')-27; $i--){
$x = $i +1;
$y = $i;
echo '<option value='.$y.'-'.$x.'>'.$y.'-'.$x.'</option>';
}?>
</select>
Result:
[0]Choose School Year
[1] Present
[2] 2017-2018
[3] 2016-2017 if selected index[3] / How can i pass 3 in my 2nd for loop?
2015-2016 for($i=date('Y'); $i > date('Y')-3; $i--)/See below php code..
[5]2014-2015
[6]2013-2014
and so on ...
<label class="control-label">SY2:</label>
<select class="form-control" name="sec_sy" id="sec_sy" onchange="">
<?php
$null = 'Null';
$choose = 'Choose School Year';
$Present = 'Present';
echo '<option value='.$null.'>' .$choose.'</option>';
echo '<option value='.$Present.'>' .$Present.'</option>';
for($i=date('Y'); $i > date('Y')-3; $i--){
$x = $i +1;
$y = $i;
echo '<option value='.$y.'-'.$x.'>'.$y.'-'.$x.'</option>';
}?>
</select>
Expected Result:
Choose School Year
Present
2017-2018
2016-2017
2015-2016
<script type="text/javascript">
$('.form-control').on('change', function(e) {
var pri_sy = $("#pri_sy").find("option:selected").index();
var sec_sy = $("#sec_sy").find("option:selected").index();
var sen_high_sy = $("#sen_high_sy").find("option:selected").index();
var college_sy = $("#college_sy").find("option:selected").index();
var isPri = $(this).is("#pri_sy");
var isSec = $(this).is("#sec_sy");
var isSenHigh = $(this).is("#sen_high_sy");
var isCollege = $(this).is("#college_sy");
//console.log("from:"+fromIdx,"to:"+toIdx);
if (isPri) {
alert('a');
$('#sec_sy').val(pri_sy);
alert(pri_sy);
// $('#sec_sy').each(function(pri_sy, sec_sy) {
// $(sec_sy).attr('disabled', pri_sy < sec_sy);
});
}
}).change();
</script>
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2npSFKA
via IFTTT
Aucun commentaire:
Enregistrer un commentaire