unemployment Posted January 27, 2011 Share Posted January 27, 2011 Firebug says I have undefined variables. I'm not sure why. My if doesn't add the disable. addOnload(function(){ var country = document.accountsettings.country.selectedIndex; var country_text = document.accountsettings.country.options[country].text; if(country_text != 'United States') { document.getElementById('state').disabled=true; } else { document.getElementById('state').disabled=false } }); Quote Link to comment https://forums.phpfreaks.com/topic/225863-disable-dropdown-not-working/ Share on other sites More sharing options...
ManiacDan Posted January 27, 2011 Share Posted January 27, 2011 I see a missing semicolon. I don't see any debug information. Are you sure these accountsettings lines are pulling valid data? -Dan Quote Link to comment https://forums.phpfreaks.com/topic/225863-disable-dropdown-not-working/#findComment-1166039 Share on other sites More sharing options...
Psycho Posted January 27, 2011 Share Posted January 27, 2011 I'm assuming that "accountsettings" is the name of a form and that "country" is the name of a select field. Although the way you are referencing the field usually works, it is not the preferred method. I would suggest referencing the select field by ID (option 1) or refrence explicitly (option 2) Option 1 var selectObj = document.getElementById('country'); var country_text = selectObj.options[selectObj.selectedIndex].text; Option 2 var selectObj = document.forms['accountsettings'].elements['country']; var country_text = selectObj.options[selectObj.selectedIndex].text; Quote Link to comment https://forums.phpfreaks.com/topic/225863-disable-dropdown-not-working/#findComment-1166226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.