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 Coder
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Validates against multiple dropdown menus

    i want to validate against the dropdown fields below name usrchoices which repeat depends upon the data records from database...so if there is 5 questions retrieved from the database then the 5 dropdowns appears with name usrchoices, i don't know how to validate all these fields...so please any one here fix the following code and send me....Thanks a Million

    <script language="JavaScript"><!--
    function validating(validate) {
    **if (form.usrchoices.selectedIndex == 0) {
    ****alert('Please select all Questions');
    ****document.getElementById("validate").reset();
    *
    ****return false;

    **}
    **return true;
    }
    //--></script>

    <form action="submitsurvey.asp" method="post" name="validate" id="validate" onSubmit="return validating()">
    <% Do while Recordset_questions.EOF %>
    ****<select name="usrchoices" id="usrchoices">
    **********<option value="" selected>Select Choices</option>
    **********<option value="Y">Yes</option>
    **********<option value="N">No</option>
    **********<option value="IDK">I Dont know</option>
    ********</select>
    <%Loop%>
    </form>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Your five select boxes may not all have the same name userchoices.

    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.

  • Users who have thanked Philip M for this post:

    Sydhussain2010 (02-27-2012)

  • #3
    New Coder
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Can u kindly guide me with the example?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    I should have said that your select lists may not have the same id.

    Code:
    <form name= "myform">
    QUESTION 1 
    <select name = "usrchoices">
    <option value="" selected>Select Choices</option>
    <option value="Y">Yes</option>
    <option value="N">No</option>
    <option value="IDK">I Dont know</option>
    </select>
    QUESTION 2 
    <select name = "usrchoices">
    <option value="" selected>Select Choices</option>
    <option value="Y">Yes</option>
    <option value="N">No</option>
    <option value="IDK">I Dont know</option>
    </select>
    QUESTION 3 
    <select name = "usrchoices">
    <option value="" selected>Select Choices</option>
    <option value="Y">Yes</option>
    <option value="N">No</option>
    <option value="IDK">I Dont know</option>
    </select>
    <br><br>
    
    <input type = "button" value = "Check How Many Answered" onclick = "validating()">
    
    </form>
    
    <script type = "text/javascript">
    
    function validating() {
    var allSelects = document.getElementsByTagName("select");
    var len = allSelects.length;
    var notOK = 0;
    for (var i=0; i<len; i++) {
    if (allSelects[i].selectedIndex == 0) {
    notOK ++;
    }
    }
    if (notOK > 0) {
    alert ("You have not selected an answer to "  + notOK + " of the questions!");
    return false;
    }
    else {alert ("Thank you for answering all of the questions!");
    return true;
    }
    
    }
    
    </script>
    Last edited by Philip M; 02-25-2012 at 07:38 PM.

    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.

  • Users who have thanked Philip M for this post:

    Sydhussain2010 (02-27-2012)

  • #5
    New Coder
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    11
    Thanked 0 Times in 0 Posts

    its showing the un selected number of fields but it submits the form

    First of all God Bless you.... Thank you so much....you are the cause of smile on my face

    Now only the problem is....its showing the unselected number of fields but it submits the form after alerts...i need to highlight the unselected fields in red and reset the all form and not allows the user to submit the form unless he select from each dropdown menu.

    Thanks & Best Regards
    syed

  • #6
    New Coder
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    11
    Thanked 0 Times in 0 Posts

    how i can refresh my main history page without error?

    how i can refresh my main history page without the attached error?

    i am using the following code on the submitpage.asp

    <%response.write ("<script>window.location.reload(history.go(-2));</script>")%>

    i got the attached message when it refreshes the main page.

    is there is a way to refresh directly without this message?
    Attached Thumbnails Attached Thumbnails Validates against multiple dropdown menus-error_message.jpg  

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by Sydhussain2010 View Post
    Now only the problem is....its showing the unselected number of fields but it submits the form after alerts...i need to highlight the unselected fields in red and reset the all form and not allows the user to submit the form unless he select from each dropdown menu.
    The form will not submit if all the selections have not been made. Did you not notice

    Code:
    if (notOK > 0) {
    alert ("You have not selected an answer to "  + notOK + " of the questions!");
    return false;
    Use CSS to highlight the unselected fields in red.

    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.

  • Users who have thanked Philip M for this post:

    Sydhussain2010 (02-27-2012)

  • #8
    New Coder
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Unhappy <%response.write ("<script>window.location.reload(history.go(-2));</script>")%>

    Dear Philip,

    All validation is working fine, now only one issue i have, i want to refresh the main history page so i add <%response.write ("<script>window.location.reload(history.go(-2));</script>")%> on submitquestion page....its working fine on the Internet Explorer 8 but on Internet Explorer 9 it refreshing 100 times and refresh message come again and again.

    Please guide me
    Thanks
    Syed


  •  

    Posting Permissions

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