Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Location
    England
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    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.

  • #3
    New Coder
    Join Date
    Jul 2011
    Location
    Kediri - Indonesia
    Posts
    61
    Thanks
    2
    Thanked 19 Times in 19 Posts
    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>

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    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.

    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.

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Location
    England
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    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.

  • #7
    New to the CF scene
    Join Date
    Nov 2010
    Location
    England
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #8
    New Coder
    Join Date
    Jul 2011
    Location
    Chennai, India
    Posts
    23
    Thanks
    0
    Thanked 5 Times in 5 Posts
    This could help you.
    If problem persists, let me know
    Attached Files Attached Files


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •