lucy Posted September 9, 2009 Share Posted September 9, 2009 Why does the following code work in dreamweaver live view but not firefox or internet explorer? Its meant to enable the second combo box if the first value is 1 and enable the third combo box if the first value is 2. code below: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function updateList1(optionValue){ if(optionValue=='1'){list2.disabled = false;}else {list2.disabled = true;} if(optionValue=='2'){list3.disabled = false;}else {list3.disabled = true;} } </script> </head> <body> <select name="list1" id="list1" onchange="updateList1(this.value)"> <option selected></option> <option value="1">1</option> <option value="2">2</option> </select> <select name="list2" id="list2" disabled="disabled"> <option selected></option> <option value="one">one</option> <option value="two">two</option> </select> <select name="list3" id="list3" disabled="disabled"> <option selected></option> <option value="apple">apple</option> <option value="pie">pie</option> </select> </select> </body> </html> Thanks for any help Lucy Quote Link to comment https://forums.phpfreaks.com/topic/173676-solved-combo-enabledisable/ Share on other sites More sharing options...
Psycho Posted September 9, 2009 Share Posted September 9, 2009 It works for me in IE7 but not in FF3. I believe the problem is that your reference to the other two select lists is not complete. It looks liek the code is trying to reference them only by their name, but not giving any "context" of that name. If they were in a form you could reference them via the form object like so document.forms['formName'].elements['fieldname'] But, in this case I would just use getElementById(). Also, you don't need full If/Esle satements, simply assign the disabled value of the other two select lists based upon the value of select list 1. function updateList1(optionValue) { document.getElementById('list2').disabled = (optionValue!='1'); document.getElementById('list3').disabled = (optionValue!='2'); } Quote Link to comment https://forums.phpfreaks.com/topic/173676-solved-combo-enabledisable/#findComment-915547 Share on other sites More sharing options...
lucy Posted September 10, 2009 Author Share Posted September 10, 2009 How could i extend this, so an alert box popped up when list1 was changed to option value 3? Thanks, Lucy Quote Link to comment https://forums.phpfreaks.com/topic/173676-solved-combo-enabledisable/#findComment-916170 Share on other sites More sharing options...
Psycho Posted September 11, 2009 Share Posted September 11, 2009 Um: function updateList1(optionValue) { document.getElementById('list2').disabled = (optionValue!='1'); document.getElementById('list3').disabled = (optionValue!='2'); if (optionValue=='3') { alert('foo'); } } Quote Link to comment https://forums.phpfreaks.com/topic/173676-solved-combo-enabledisable/#findComment-916508 Share on other sites More sharing options...
lucy Posted September 13, 2009 Author Share Posted September 13, 2009 thanks a lot Lucy Quote Link to comment https://forums.phpfreaks.com/topic/173676-solved-combo-enabledisable/#findComment-917602 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.