472,127 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Problem with disabled select

263 100+
Problem with disabled select

Hi all.

I have this form:

Expand|Select|Wrap|Line Numbers
  1. <select size="1" name="FRG_FNC">
  2.             <option value="">Select value</option>
  3.             <option value="FRC">FRG</option>
  4.             <option value="FNC">FNC</option>
  5.             <option value="No">No</option>
  6. </select>
  7.  
  8.  
  9. <select size="1" name="core" onchange="var cc = this.options[this.selectedIndex].value; if(cc=='No')Forum();">          
  10.                   <option value="">Select value</option>
  11.                   <option value="Yes">Yes</option>
  12.                   <option value="No">No</option>
  13. </select>
  14.  
  15. <input type="text" name="code" size="10" readonly value="-"></p>
I need:

1) if value = No in the select name="FRG_FNC" disabled the select name="core" and the input type="text" name="code"

2) if value = No in the select name="FRG_FNC" assign a default value in the select name="FRG_FNC" and the input type="text" name="code"


Can you help me?
Aug 27 '08 #1
5 1151
gits
5,390 Expert Mod 4TB
i'm quite unsure about your 2. point ... you want to select 'NO' in the first select ... the value should be switched to another one? then the point 1 is quite obsolete since you will not need the 'NO'-option there? may be i just don't get it right? ... or you mean the 'core'-select here in point 2.?

kind regards
Aug 27 '08 #2
viki1967
263 100+
Problem solved thanks; I change the data form
kind regards and thanks x your reply.
Aug 28 '08 #3
gits
5,390 Expert Mod 4TB
glad to hear you solved your problem ... may be you could just drop a short note regarding your solution ... just for the users that may find this thread in the future and have a similar problem?

kind regards
Aug 28 '08 #4
viki1967
263 100+
glad to hear you solved your problem ... may be you could just drop a short note regarding your solution ... just for the users that may find this thread in the future and have a similar problem?

kind regards
Ok, no problem.

Some people won't like me using id values here but I will in this case for simplicity's sake:

Expand|Select|Wrap|Line Numbers
  1. <select id="FRG_FNC" size="1" name="FRG_FNC">
  2.             <option value="">Select value</option>
  3.             <option value="FRC">FRG</option>
  4.             <option value="FNC">FNC</option>
  5.             <option value="No">No</option>
  6. </select>
  7.  
  8.  
  9. <select id="core" size="1" name="core">          
  10.                   <option value="">Select value</option>
  11.                   <option value="Yes">Yes</option>
  12.                   <option value="No">No</option>
  13. </select>
  14.  
  15. <input id="code" type="text" name="code" size="10" readonly value="-"
  16.  
In an external .js file which you'll link to in the head of your html page write:

Expand|Select|Wrap|Line Numbers
  1. window.onload = initSelects;
  2.  
  3. function initSelects()   {
  4.    var sel1 = document.getElementById("FRG_FNC");
  5.    if (sel1)   {
  6.       sel1.onchange = sel1Change;
  7.    }
  8.    var sel2 = document.getElementById("core");
  9.    if (sel2)   {
  10.       sel2.onchange = sel2Change;
  11.    }
  12. }
  13. function sel1Change()   {
  14.    var sel2 = document.getElementById("core");
  15.    var code = document.getElementById("code");
  16.    if (this.selectedIndex === 3)   {
  17.       sel2.selectedIndex = 2;
  18.       sel2.disabled = true;
  19.       code.value = "default";
  20.       code.disabled = true;
  21.    } else   {
  22.       sel2.selectedIndex = 0;
  23.       sel2.disabled = false;
  24.       code.value = "";
  25.       code.disabled = false;     
  26.    }
  27. }
  28. function sel2Change()   {
  29.    var cc = this.options[this.selectedIndex].value;
  30.    if(cc === 'No') Forum();
  31. }
  32.  
kind regards
viki
Aug 28 '08 #5
gits
5,390 Expert Mod 4TB
thanks for sharing your solution :)

kind regards
Aug 28 '08 #6

Post your reply

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

Similar topics

12 posts views Thread by Pudlik, Szymon | last post: by
1 post views Thread by novice_developer | last post: by
5 posts views Thread by comshiva | last post: by
3 posts views Thread by lolodede | last post: by
pradeepjain
4 posts views Thread by pradeepjain | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.