...

View Full Version : Validates against multiple dropdown menus



Sydhussain2010
02-25-2012, 05:23 PM
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>

Philip M
02-25-2012, 05:28 PM
Your five select boxes may not all have the same name userchoices.

Sydhussain2010
02-25-2012, 07:37 PM
Can u kindly guide me with the example?

Philip M
02-25-2012, 08:27 PM
I should have said that your select lists may not have the same id.


<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>

Sydhussain2010
02-25-2012, 09:45 PM
First of all God Bless you.... Thank you so much....you are the cause of smile on my face:):thumbsup:

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

Sydhussain2010
02-26-2012, 06:35 AM
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?

Philip M
02-26-2012, 09:54 AM
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


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.

Sydhussain2010
02-27-2012, 06:44 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum