I’ll explain my situation with the codes.
HTML:
<div class="list1">
<select class="select250">
<option class="temp" selected="selected" name="filter[]">Select</option>
<option class="" value="George" name="filter[]">George</option>
<option class="" value="Ben" name="filter[]">Ben</option>
</select>
</div>
<div class="list2">
<select class="select251">
<option class="temp" selected="selected" name="filter[]">Select</option>
<option class="" value="Sarah" name="filter[]">Sarah</option>
<option class="" value="Alex" name="filter[]">Alex</option>
<option class="" value="Natalie" name="filter[]">Natalie</option>
</select>
</div>
<div class="list3">
<select class="select252">
<option class="temp" selected="selected" name="filter[]">Select</option>
<option class="" value="Mobile" name="filter[]">Mobile</option>
<option class="" value="Car" name="filter[]">Car</option>
<option class="" value="Computer" name="filter[]">Computer</option>
</select>
</div>
JS (this is used within PHP):
<script type="text/javascript">
$('.select<?php echo $sid?>').change(function() {
$('.temp', this).remove(); // THIS IS FINE
if ($('option').siblings('.temp')) { }
else { $('select').prepend('<option name="filter[]" selected="selected" class="temp">Select</option>'); // THIS IS NOT WORKING
}
});
</script>
What I wanted to do is – whenever an option is selected, it should remove the “Select” option within that list but still keep “Select” option on other lists. This part seems to be working fine. The next thing to do is – when an option is selected on another list, it should bring back select on all the other lists except for the one where it is selected. I tried writing a code for it as you can see above but couldn’t move past it. If someone can guide me in the right direction, that’ll be awesome. Thanks.
Try this.. This can still be optimized..
Check Fiddle