Skip to content

Instantly share code, notes, and snippets.

@thanashyam
Created August 14, 2011 14:30
Show Gist options
  • Save thanashyam/1144920 to your computer and use it in GitHub Desktop.
Save thanashyam/1144920 to your computer and use it in GitHub Desktop.
Updating values of "Age from" and "Age To" select inputs based values from the other
$('#agefrom').live('change',function() {
var age_from = parseInt($('#agefrom').val());
var age_to = parseInt($('#ageto').val());
if (age_to < age_from) {
$('#ageto option:selected').removeAttr('selected');
if (age_from < 99) {
$('#ageto option[value="'+ String(age_from + 1) + '"]').attr('selected','selected');
} else {
$('#ageto option[value="99"]').attr('selected','selected');
}
$.uniform.update("#ageto"); // For UniformJs
}
});
$('#ageto').live('change',function() {
var age_from = parseInt($('#agefrom').val());
var age_to = parseInt($('#ageto').val());
if (age_to < age_from) {
$('#agefrom option:selected').removeAttr('selected');
if (age_from < 99) {
$('#agefrom option[value="'+ String(age_to - 1) + '"]').attr('selected','selected');
} else {
$('#agefrom option[value="18"]').attr('selected','selected');
}
$.uniform.update("#agefrom"); // For UniformJs
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment