i have a form where a user can select timing intervals. But I only want that the could choose only one option. On selecting a value from a dropdown jQuery should reset the other dropdowns.
HTML (and php but not relevant):
<select class="span1" name="repeatminute" id="repeatIntervalTiming" onChange="disableOther(this)">
<?php for($i=0; $i<61;$i++){ echo "<option>$i</option>"; } ?>
</select>
minute(s)</label>
<label>
<select class="span1" name="repeathour" id="repeatIntervalTiming" onChange="disableOther(this)">
<?php for($i=0; $i<25;$i++){ echo "<option>$i</option>"; } ?>
</select>
hour(s)</label>
<label>
<label>
<select class="span1" name="repeatday" id="repeatIntervalTiming" onChange="disableOther(this)">
<?php for($i=0; $i<32;$i++){ echo "<option>$i</option>"; } ?>
</select>
day(s)</label>
<label>
<select class="span1" name="repeatmonth" id="repeatIntervalTiming" onChange="disableOther(this)">
<?php for($i=0; $i<13;$i++){ echo "<option>$i</option>"; } ?>
</select>
month(s)</label>
Here is my jQuery try:
function disableOther(caller){
$('#repeatIntervalTiming').each(function(index) {
if ($(this).text() != caller.textContent){
$(this).val(0);
}
});
There is a
.not()method in jQuery which removes element(s) from the set of matched elements.Documentation here.
PS1: Use unique IDs! I have changed your ID selector to class selector.
PS2: Avoid inline javascript if possible. My example is unobtrussive.