...

View Full Version : Setting a combolist index and value



HumphreyBumpkin
07-23-2011, 12:20 PM
Javascript

I have 3 combolist fields ( A, B and C ) each of which has just "No" and "Confirmed" as their only options.

I have one final combolist ( D ) which has just "Yes" and "No" as options. "No" is the default selected item and Index0 in the list.

The user must select "Confirm" all three ( A, B and C ) lists before they should be allowed to select "Yes" in the final list ( D ).

I want to be able to have the system to automatically select and display "No" in list ( D ) if any of the first 3 selections ( A, B or C ) are "No".

I don't have a problem validating if any of the 3 lists ( A, B or C ) are "No" but I cannot get the final combolist to change from "Yes" ( if previously selected ) to "No".

I have tried setting the selected index of (D) to 0 and tried setting the selected value of (D) to "No" but if (D) currently displays "Yes" when any of the ( A, B or C ) are changed to "No" nothing happens to (D).

Am I trying to do something that cannot be done ?

Any help will be gratefully received.

Tony

Philip M
07-23-2011, 03:56 PM
Of course it can be done.


<select id = "A" onchange = "chk()">
<option value = "No">No</option>
<option value = "Confirmed">Confirmed</option>
</select>
<select id = "B" onchange = "chk()">
<option value = "No">No</option>
<option value = "Confirmed">Confirmed</option>
</select>
<select id = "C" onchange = "chk()">
<option value = "No">No</option>
<option value = "Confirmed">Confirmed</option>
</select>
<select id = "D" onchange = "chk()">
<option value = "No" selected>No</option>
<option value = "Yes">Yes</option>
</select>

<script type = "text/javascript">
function chk() {
var a = document.getElementById("A").value;
var b = document.getElementById("B").value;
var c = document.getElementById("C").value;
if (a != "Confirmed" || b != "Confirmed" || c != "Confirmed") {
document.getElementById("D").selectedIndex = 0;
}
}

</script>


Quizmaster: How many FA Cup Final appearances has Ashley Cole made? Is it three or six?
Contestant: Four.

XterM
07-23-2011, 06:45 PM
Of course it can be done.


<select id = "A" onchange = "chk()">
<option value = "No">No</option>
<option value = "Confirmed">Confirmed</option>
</select>
<select id = "B" onchange = "chk()">
<option value = "No">No</option>
<option value = "Confirmed">Confirmed</option>
</select>
<select id = "C" onchange = "chk()">
<option value = "No">No</option>
<option value = "Confirmed">Confirmed</option>
</select>
<select id = "D" onchange = "chk()">
<option value = "No" selected>No</option>
<option value = "Yes">Yes</option>
</select>

<script type = "text/javascript">
function chk() {
var a = document.getElementById("A").value;
var b = document.getElementById("B").value;
var c = document.getElementById("C").value;
if (a != "Confirmed" || b != "Confirmed" || c != "Confirmed") {
document.getElementById("D").selectedIndex = 0;
}
}

</script>


Quizmaster: How many FA Cup Final appearances has Ashley Cole made? Is it three or six?
Contestant: Four.

the code is running well. when A, B, and C selected "confirmed", selected index of D is YES. but when values moved to NO, and then selected again, value of D not selected to yes. just small correction.


<select id = "A" onchange = "chk()">
<option value = "No">No</option>
<option value = "Confirmed">Confirmed</option>
</select>
<select id = "B" onchange = "chk()">
<option value = "No">No</option>
<option value = "Confirmed">Confirmed</option>
</select>
<select id = "C" onchange = "chk()">
<option value = "No">No</option>
<option value = "Confirmed">Confirmed</option>
</select>
<select id = "D" onchange = "chk()">
<option value = "No" selected>No</option>
<option value = "Yes">Yes</option>
</select>

<script type = "text/javascript">
function chk() {
var a = document.getElementById("A").value;
var b = document.getElementById("B").value;
var c = document.getElementById("C").value;
if (a != "Confirmed" || b != "Confirmed" || c != "Confirmed") {
document.getElementById("D").selectedIndex = 0;
}
//just add only this line
else {
document.getElementById("D").selectedIndex = 1;
}
}

</script>


:thumbsup:

Philip M
07-23-2011, 07:24 PM
XtrerM - my understanding is that what is wanted is that if A, B and C are all selected as "Confirmed" the user then has the option to select either Yes or No in Box D, but cannot select Yes if any of the three boxes are not "Confirmed".


The user must select "Confirm" all three ( A, B and C ) lists before they should be allowed to select "Yes" in the final list ( D ).

Your code automatically selects Yes in Box D if boxes A, B and C are "Confirmed". But it may be that the OP actually wanted that.

HumphreyBumpkin
07-25-2011, 12:19 PM
You have provided the code


document.getElementById("D").selectedIndex = 0;

which I have tried ( apologies for not including it with my original query as I didn't have access to it at the time ).

Is it possible to set the appropriate response by index without the display the value ( i.e. "No" ) of the selected item ? I can't get the combolist to display "No".

I can only think that I have made some other mistake. I will return to the code and try again.

Thanks for the help.

Philip M
07-25-2011, 01:12 PM
Is it possible to set the appropriate response by index without the display the value ( i.e. "No" ) of the selected item ? I can't get the combolist to display "No".



I don't understand you - the script works just fine for me, and places or maintains Box D at "No" if any of the other three boxes have "No" as the selected option. My understanding is that is what you asked for.

HumphreyBumpkin
07-25-2011, 05:51 PM
Apologies if I didn't make it clear.

I started with the code you suggested BEFORE I even posted the query.

Your suggestion confirmed that it should be working but unfortunately it doesn't. There's obviously something else that I've done which may be affecting the list.

Thanks again.

nanda.t
07-26-2011, 10:47 AM
This could help you.
If problem persists, let me know



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum