I am limited to using jquery 1.3.1 for this project, so can't update jquery. I am trying to get one select field to disable another select field on change.
I have tried this:
$(document.body).on('change','#idoffirstselect',function(){
var selected = $("#idoffirstselect").val();
if (selected == "foo") {
$("#selecttwo").attr('disabled','disabled');
} else {
$("#selecttwo").removeAttr('disabled');
}
});
And this:
$( "#idoffirstselect" ).change(function(){
var selected = $("#idoffirstselect").val();
if (selected == "foo") {
$("#selecttwo").attr('disabled','disabled');
} else {
$("#selecttwo").removeAttr('disabled');
}
});
Any suggestions? Is there anything else I could try? Firebug is not showing any errors.
Since on
is not available in version before 1.7
, try to use live() here:
$(function() {
$('select').live('change', function(){
var selected = $("#idoffirstselect").val();
if (selected == "foo") {
$("#selecttwo").attr('disabled','disabled');
} else {
$("#selecttwo").removeAttr('disabled');
}
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.