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:
-
<select size="1" name="FRG_FNC">
-
<option value="">Select value</option>
-
<option value="FRC">FRG</option>
-
<option value="FNC">FNC</option>
-
<option value="No">No</option>
-
</select>
-
-
-
<select size="1" name="core" onchange="var cc = this.options[this.selectedIndex].value; if(cc=='No')Forum();">
-
<option value="">Select value</option>
-
<option value="Yes">Yes</option>
-
<option value="No">No</option>
-
</select>
-
-
<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
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
Problem solved thanks; I change the data form
kind regards and thanks x your reply.
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
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:
-
<select id="FRG_FNC" size="1" name="FRG_FNC">
-
<option value="">Select value</option>
-
<option value="FRC">FRG</option>
-
<option value="FNC">FNC</option>
-
<option value="No">No</option>
-
</select>
-
-
-
<select id="core" size="1" name="core">
-
<option value="">Select value</option>
-
<option value="Yes">Yes</option>
-
<option value="No">No</option>
-
</select>
-
-
<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:
-
window.onload = initSelects;
-
-
function initSelects() {
-
var sel1 = document.getElementById("FRG_FNC");
-
if (sel1) {
-
sel1.onchange = sel1Change;
-
}
-
var sel2 = document.getElementById("core");
-
if (sel2) {
-
sel2.onchange = sel2Change;
-
}
-
}
-
function sel1Change() {
-
var sel2 = document.getElementById("core");
-
var code = document.getElementById("code");
-
if (this.selectedIndex === 3) {
-
sel2.selectedIndex = 2;
-
sel2.disabled = true;
-
code.value = "default";
-
code.disabled = true;
-
} else {
-
sel2.selectedIndex = 0;
-
sel2.disabled = false;
-
code.value = "";
-
code.disabled = false;
-
}
-
}
-
function sel2Change() {
-
var cc = this.options[this.selectedIndex].value;
-
if(cc === 'No') Forum();
-
}
kind regards
viki
thanks for sharing your solution :)
kind regards
|
|
|
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.
Top Javascript / DHTML / Ajax Contributors
|