By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,824 Members | 2,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,824 IT Pros & Developers. It's quick & easy.

how to disable another dropdown list if one is selected

P: 1
this is my code, i want to disable student label dropdown if i select teacher dropdown list and vice versa.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function df()
  5.  {
  6.     var i=teacher;
  7.  
  8.         if(i==document.getElementById("teacher"))
  9.         {
  10.             document.getElementById("courses").disabled = true;
  11.             exit();
  12.         }
  13.         else
  14.         {
  15.              document.getElementById("teacher").disabled = true;
  16.              exit();
  17.         }
  18.     }
  19.  
  20.  
  21. </script>
  22. </head>
  23. <body>
  24.  
  25. <div id="compose">
  26. <form>
  27. <table>
  28. <tr>
  29. <td>
  30. <font id="c1">TEACHER:</font></td>
  31. <td><select name="teacher" id="teacher" onChange="df()">
  32. <option value="t1">t1</option>
  33. <option value="t2">t2</option>
  34. </select></td>
  35. </tr>
  36. <tr>
  37. <td>
  38. <font id="c1">STUDENT:</font></td><td> <select name="courses" id="courses" onChange="df()">
  39. <option value="1">DIPLOMA</option>
  40. <option value="2">CERTIFICATE</option>
  41. </select><br/> </td> </tr>
  42. <tr>
  43. <td>
  44. <font id="c1">SUBJECT:</font><input type="text" name="to" id="to"/>
  45. </td></tr>
  46. <tr>
  47. <td>
  48.  
  49. <font id="c1">MESSAGE:</font></td></tr>
  50. <tr>
  51. <td>
  52. <textarea rows="4" cols="50">
  53. At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.
  54. </textarea></td></tr> 
  55.  
  56. <tr>
  57. <td>
  58. <input type="button" value="SEND"></td></tr>
  59. </table>
  60. </form>
  61. </div>
  62. </body>
  63. </html>
Mar 29 '14 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
there are some general flaws in the design + some errors.

first the errors:
- exit() is not a native JS function. JS will throw a fatal parser error there

flaws:
the variable teacher is not defined and hence receives its value from the system mapping pointing to the teacher dropdown. that wonít change. hence your first condition will always trigger. (even when you select in the student dropdown)

but even if i could change its value, a disabled dropdown will never respond to any event (thatís why it is disabled) and wonít be submitted either.
Mar 29 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.