Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-23-2011, 12:20 PM   PM User | #1
HumphreyBumpkin
New to the CF scene

 
Join Date: Nov 2010
Location: England
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
HumphreyBumpkin is an unknown quantity at this point
Question Setting a combolist index and value

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
HumphreyBumpkin is offline   Reply With Quote
Old 07-23-2011, 03:56 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Of course it can be done.

Code:
<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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 07-23-2011, 06:45 PM   PM User | #3
XterM
New Coder

 
Join Date: Jul 2011
Location: Kediri - Indonesia
Posts: 61
Thanks: 2
Thanked 19 Times in 19 Posts
XterM is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
Of course it can be done.

Code:
<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.
Code:
<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>
XterM is offline   Reply With Quote
Old 07-23-2011, 07:24 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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".

Quote:
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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 07-25-2011, 12:19 PM   PM User | #5
HumphreyBumpkin
New to the CF scene

 
Join Date: Nov 2010
Location: England
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
HumphreyBumpkin is an unknown quantity at this point
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.
HumphreyBumpkin is offline   Reply With Quote
Old 07-25-2011, 01:12 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by HumphreyBumpkin View Post
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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 07-25-2011, 05:51 PM   PM User | #7
HumphreyBumpkin
New to the CF scene

 
Join Date: Nov 2010
Location: England
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
HumphreyBumpkin is an unknown quantity at this point
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.
HumphreyBumpkin is offline   Reply With Quote
Old 07-26-2011, 10:47 AM   PM User | #8
nanda.t
New Coder

 
Join Date: Jul 2011
Location: Chennai, India
Posts: 23
Thanks: 0
Thanked 5 Times in 5 Posts
nanda.t is an unknown quantity at this point
This could help you.
If problem persists, let me know
Attached Files
File Type: zip 3_cbx_to_4.zip (672 Bytes, 17 views)
nanda.t is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:19 PM.


Advertisement
Log in to turn off these ads.