O.k,
Still having issue now when the user answers a question(checks) at
least one check box for each question I still get the javascript error
"not all questions answered" and this is when it should submit to the
thankyou.asp page.
here is the HTML
<HEAD>
<TITLE>Survey</TITLE>
<script language="JavaScript">
<!--
//Detect IE5.5+
version=0
if (navigator.appVersion.indexOf("MSIE")!=-1){
temp=navigator.appVersion.split("MSIE")
version=parseFloat(temp[1])
}
if (version < 5.02) {
window.location="include/error.html";
}
function validateCheckBoxes(){
var bOK = true;
var bFlag = false;
var iCheckboxCount = 0;
var iQuestionCount = document.getElementById('QuestionCount').value;
for (var i=1; i <= iQuestionCount; i++) {
bFlag = false;
iCheckboxCount = document.getElementById('cbCount' + i).value;
for (var j=1; j <= iCheckboxCount; j++) {
if (document.getElementById("chk" + i + "_" + j).checked) {
bFlag = true;
}
}
if (!bFlag) { bOK = false; }
}
if (!bOK) {
alert("not all questions answered");
return false;
} else {
return true;
//var oForm = document.SurveySubmitted;//change to real name
//oForm.submit();
}
}
//-->
</script>
</head>
<CENTER>
<BODY leftmargin="0" rightmargin="0" marginwidth="0" topmargin="0"
marginheight="0" bottommargin="0" bgcolor="#ffffff">
<table width="60%" cellspacing="0" cellpadding="5">
<hr>
<font size=5>
<center><b>IT Survey Request</center></b>
<HR>
</font>
<p>
<form action="testSubmission.asp" method="post" name="SurveySubmitted">
<input type="hidden" name="HiddenSurveyID" value="1">
<input type="hidden" name="HiddenQuestionID" value="1">
<b>1. Which of the following RIM Communication vehicles do you read
regularly? Please mark all that apply.</b><p>
<input type="checkbox" id="chk1_1" Name="Question1" Value="a">Dispatch
Newsletter</input><br>
<input type="checkbox" id="chk1_2" Name="Question1" Value="b">General
Notifications(email)</input><br>
<input type="checkbox" id="chk1_3" Name="Question1" Value="c">Intranet
Homepage (InSite)</input><br>
<input type="checkbox" id="chk1_4" Name="Question1" Value="d">IT
Service Desk Corporate Notifications</input><br>
<input type="checkbox" id="chk1_5" Name="Question1" Value="e">Team
Websites (
http://go/it,
http://go/cso etc.)</input><br>
<BR>Other<BR><textarea name="textBoxAnswer1" rows="2"
cols="50"></textarea>
<input type="hidden" name="HiddenTextValue" value="f">
<p><b>2. Please select the 3 most helpful means of
communication?</b><p>
<input type="hidden" id="cbCount1" value="5"><input type="checkbox"
id="chk2_1" Name="Question2" Value="a">Online Newsletter</input><br>
<input type="checkbox" id="chk2_2" Name="Question2" Value="b">Print
Newsletter</input><br>
<input type="checkbox" id="chk2_3" Name="Question2" Value="c">Intranet
homepage (Insite)</input><br>
<p><b>3. Please select the three least helpful means of
communication</b><p>
<p><b>5. To ensure you stay well informed about IT services, projects
and updates, what communication vehicle would you read? Please select
one</b><p>
<p><input type="hidden" id="cbCount2" value="3"><input type="hidden"
id="QuestionCount" value="2">
<hr>
</TABLE>
<TABLE>
<TR>
<TD COLSPAN=3 ALIGN="center"><BR>
<input type=submit value="Submit" ONCLICK="return
validateCheckBoxes();">
</TD>
</TR>
</TABLE>
</FORM>
</CENTER>
Ben said:
O.K Ben I have made the changes and I no longer get the error. Any
ideas why the error with the numeric.
Good! Not sure exactly, however it may have to do with the exact numeric
type -- integer, long, decimal, double, etc. Converting everything to a
string avoids this.
Also,
I have added the javascript code and did not fill in any check boxes.
I did receive the error "not all questions answered" both when the user
would not fill in checkboxes and when he/she fills in checkboxes. So
it's not working accordingly. It also proceeds to my thankyou.asp page
with having the user first correct the missing checked checkboxes. Any
ideas?
To avoid going to the thankyou.asp page when not all questions are answered,
you'll want to make two changes:
[1] Change your submit button HTML to:
<input type=submit value="Submit"
ONCLICK="return validateCheckBoxes();">
[2] Change the JavaScript to the following:
function validateCheckBoxes(){
var bOK = true;
var bFlag = false;
var iCheckboxCount = 0;
var iQuestionCount = document.getElementById('QuestionCount').value;
for (var i=1; i <= iQuestionCount; i++) {
bFlag = false;
iCheckboxCount = document.getElementById('cbCount' + i).value;
for (var j=1; j <= iCheckboxCount; j++) {
if (document.getElementById("chk" + i + "_" + j).checked) {
bFlag = true;
}
}
if (!bFlag) { bOK = false; }
}
if (!bOK) {
alert("not all questions answered");
return false;
} else {
return true;
//var oForm = document.SurveySubmitted;//change to real name
//oForm.submit();
}
}
-------------------------------------
If there's any other problems remaining, please post the rendered HTML
(right-click, View Source).
Ben