sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
viki1967's Avatar

Problem with disabled select


Question posted by: viki1967 (Familiar Sight) on August 27th, 2008 02:54 PM
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?
5 Answers Posted
gits's Avatar
gits August 27th, 2008 10:28 PM
Moderator - 3,369 Posts
#2: Re: Problem with disabled select

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
viki1967's Avatar
viki1967 August 28th, 2008 08:53 AM
Familiar Sight - 212 Posts
#3: Re: Problem with disabled select

Problem solved thanks; I change the data form
kind regards and thanks x your reply.
gits's Avatar
gits August 28th, 2008 08:57 AM
Moderator - 3,369 Posts
#4: Re: Problem with disabled select

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
viki1967's Avatar
viki1967 August 28th, 2008 09:31 AM
Familiar Sight - 212 Posts
#5: Re: Problem with disabled select

Quote:
Originally Posted by gits
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="-"


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. }


kind regards
viki
gits's Avatar
gits August 28th, 2008 11:08 AM
Moderator - 3,369 Posts
#6: Re: Problem with disabled select

thanks for sharing your solution :)

kind regards
Reply
Not the answer you were looking for? Post your question . . .
197,038 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,038 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Javascript / DHTML / Ajax Contributors