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

Help with disable function in javascript

P: 3
HI. I have a dropdown menu named arrivalcity (options are Rome, Naples, Palermo, and CAtania).
I also have 4 other dropdown menus which have departure dates for those cities.

Basically I want those 4 dropdown menus disabled by default. Then based on which arrivalcity
option they choose only one of those 4 dropdown menus gets enabled so they can select the departure date from the appropriate menu.
I know this can get accomplished in javascript, but I don't know where to start. Please help. I'm getting desperate to accomplish this.


The following is what I have so far:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function selChk(obj) 
  3. {
  4.              var rome_dep = document.getElementById('arrivaldate_rome');
  5.             var naples_dep = document.getElementById('arrivaldate_rome');
  6.             var palermo_dep = document.getElementById('arrivaldate_rome');
  7.             var catania_dep = document.getElementById('arrivaldate_rome');
  8.  
  9.       if(obj.value!= 'nose1') 
  10.               {
  11.                 if (obj.value = 'rome')
  12.                 {
  13.                  rome_dep.disabled = false;
  14.                     naples_dep.disabled = true;
  15.                    palermo_dep.disabled = true;
  16.                     catania_dep.disabled = true;
  17.                 }
  18.                 else if (obj.value = 'naples')
  19.                 {
  20.                  rome_dep.disabled = true;
  21.                     naples_dep.disabled = false;
  22.                    palermo_dep.disabled = true;
  23.                     catania_dep.disabled = true;
  24.                 } 
  25.                 else if (obj.value = 'palermo')
  26.                 {
  27.                  rome_dep.disabled = true;
  28.                     naples_dep.disabled = true;
  29.                    palermo_dep.disabled = false;
  30.                     catania_dep.disabled = true;
  31.                 } 
  32.                 else
  33.                 {
  34.                  rome_dep.disabled = true;
  35.                     naples_dep.disabled = true;
  36.                    palermo_dep.disabled = true;
  37.                     catania_dep.disabled = false;
  38.                 } 
  39.  
  40.        else 
  41.        {
  42.  
  43.             rome_dep.disabled = true;
  44.             naples_dep.disabled = true;
  45.             palermo_dep.disabled = true;
  46.             catania_dep.disabled = true;
  47.  
  48.        }
  49.  
  50. }
  51. </script>
  52.  
  53. <html>
  54. <body>
  55. <select name="arrivalcity" size="1" id="arrivalcity" maxlength="25" ononchange="selChk(this);">
  56.                                 <option value="nose1">please select</option>
  57.  
  58.                                 please select
  59.                               <option value="Rome">Rome</option>
  60.                               <option value="Naples">Naples</option>
  61.                               <option value="Palermo">Palermo</option>
  62.                               <option value="Catania">Catania</option>
  63.                               <option value="Other">Other</option>
  64.                                                         </select>
  65. </body>
  66. </html>
  67.  
Any help would greatly be appreciated. Thanks!
Mar 30 '09 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Perhaps you only want to show one at a time (for that, use the style.display property - "block" to show and "none" to hide.

If you want to show all of them at once but some disabled, in your code Naples, Palermo and Catania are getting the same object as Rome!
Mar 31 '09 #2

Post your reply

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