By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 769 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Checkbox Validation on Dynamic ASP Checkboxes

P: n/a
Hello Experts,

I have been told to post this in the Javascript forum as I want to do
this client side just before my form gets submitted. Once the user
clicks the submit button a javascript function needs to run and
validate all the checkboxes on my form and make sure none of them are
unchecked. I suck at Javascript and my problem is 2fold. I have the
following code that constructs the checkbox
Expand|Select|Wrap|Line Numbers
  1. response.write "<input type=checkbox Name=""Question" &
  2. objRS("Question_ID") & """ Value=""" & objTxt("Sub_Text") & """>" &
  3. objTxt("Text") & "<br>" & chr(13) 
Better yet here is my source code just in case you need it
[code]
<form action="testSubmission.asp?Survey=" 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 Name="Question1" Value="a">Dispatch Newsletter<br>
<input type=checkbox Name="Question1" Value="b">General
Notifications(email)<br>
<input type=checkbox Name="Question1" Value="c">Intranet Homepage
(InSite)<br>
<input type=checkbox Name="Question1" Value="d">IT Service Desk
Corporate Notifications<br>
<input type=checkbox Name="Question1" Value="e">Team Websites
(http://go/it, http://go/cso etc.)<br>
<BR>Other<BR><textarea name="textBoxAnswer1" ></textarea>
<input type="hidden" name="HiddenTextValue" value="f">
<p><b>2. Please select the 3 most helpful means of
communication?</b><p>
<input type=checkbox Name="Question2" Value="a">Online Newsletter<br>
<input type=checkbox Name="Question2" Value="b">Print Newsletter<br>
<input type=checkbox Name="Question2" Value="c">Intranet homepage
(Insite)<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>
<hr>
</TABLE>
<TABLE>
<TR>
<TD COLSPAN=3 ALIGN="center"><BR>
<input type=submit value="Submit" ONCLICK="javascript function;">
</TD>
</TR>
</TABLE>
[code]

With this code I need to create a javascript function and all the code
that I found refers to the check box name in the code. I however, have
no idea how to refer to my checkbox name because it is created from
database columns as shown in the above code right before the HTML
source code. Your help is greatly appreciated.

Here is the code I found but please if you have something better then
this please help. Thanks again

Expand|Select|Wrap|Line Numbers
  1. function validateCheckBoxes(){
  2. var oForm = document.SurveySubmitted;//change to real name
  3. var oCheck = oForm.HiddenTextValue;//change to real name
  4. var flag = false;
  5. var i;
  6. if(!oCheck.length&&oCheck.checked)flag = true;
  7. else{for(i=0;i<oCheck.length;i++)if(oCheck[i].checked)flag=true;}
  8. if(!flag){alert("you haven't checked anything");return false;}
  9. else oForm.submit();
  10. }
  11.  
Jun 13 '06 #1
Share this Question
Share on Google+
34 Replies


P: n/a
cl********@hotmail.com wrote:
I have the
following code that constructs the checkbox
Expand|Select|Wrap|Line Numbers
  1.  response.write "<input type=checkbox Name=""Question" &
  2.  objRS("Question_ID") & """ Value=""" & objTxt("Sub_Text") & """>" &
  3.  objTxt("Text") & "<br>" & chr(13) 

With this code I need to create a javascript function and all the code
that I found refers to the check box name in the code. I however, have
no idea how to refer to my checkbox name because it is created from
database columns as shown in the above code right before the HTML
source code. Your help is greatly appreciated.


Hi. Here's a pretty decent approach:

1. Assign each checkbox a unique ID using sequential numbers (chk1, chk2 ...
chk7). In your ASP code, you can do this by creating an integer variable
you increment by 1 each time you output a checkbox control.

2. Store the largest sequential number in a hidden field (for example, 7).

3. In validation routine, use a "for" loop -- looping from 1 thru 7 --
checking the status of each checkbox.

Ben
Jun 13 '06 #2

P: n/a

Ben Amada wrote:
cl********@hotmail.com wrote:
I have the
following code that constructs the checkbox
Expand|Select|Wrap|Line Numbers
  1.  > response.write "<input type=checkbox Name=""Question" &
  2.  > objRS("Question_ID") & """ Value=""" & objTxt("Sub_Text") & """>" &
  3.  > objTxt("Text") & "<br>" & chr(13) 

With this code I need to create a javascript function and all the code
that I found refers to the check box name in the code. I however, have
no idea how to refer to my checkbox name because it is created from
database columns as shown in the above code right before the HTML
source code. Your help is greatly appreciated.


Hi. Here's a pretty decent approach:

1. Assign each checkbox a unique ID using sequential numbers (chk1, chk2 ...
chk7). In your ASP code, you can do this by creating an integer variable
you increment by 1 each time you output a checkbox control.

2. Store the largest sequential number in a hidden field (for example, 7).

3. In validation routine, use a "for" loop -- looping from 1 thru 7 --
checking the status of each checkbox.

Ben


Hi Ben,

I'm going to have to say I don't understand. I do not wish to change
the structure since everything is working fine up until this point.
Could you clarify your point with some code. Sorry.

Jun 13 '06 #3

P: n/a
cl********@hotmail.com wrote:
Ben Amada wrote:

Hi. Here's a pretty decent approach:

1. Assign each checkbox a unique ID using sequential numbers (chk1, chk2
... chk7). In your ASP code, you can do this by creating an integer
variable you increment by 1 each time you output a checkbox control.

2. Store the largest sequential number in a hidden field (for example,
7).

3. In validation routine, use a "for" loop -- looping from 1 thru 7 --
checking the status of each checkbox.

Ben


Hi Ben,

I'm going to have to say I don't understand. I do not wish to change
the structure since everything is working fine up until this point.
Could you clarify your point with some code. Sorry.


The code below is untested, but should get you close to what you're looking
for with few changes to what you've already got:

=== ASP code ===

Dim iCheckboxID As Integer
iCheckboxID = 0

While Not objRS.EOF

iCheckboxID = iCheckboxID + 1

response.write "<input type=""checkbox"" id=""" & _
"chk" & iCheckboxID & """ Name=""Question" & _
objRS("Question_ID") & """ Value=""" & _
objTxt("Sub_Text") & """>" & _
objTxt("Text") & "<br>" & chr(13)

objRS.MoveNext

End While

response.write "<input type=""hidden"" " & _
"id=""CheckboxCount"" " & _
"value=""" & iCheckboxID & """>"

=== JavaScript code ===

function validateCheckBoxes(){
var bFlag = false;
var iCheckboxCount = document.getElementById('CheckboxCount').value;
for (var i=1; i <= iCheckboxCount; i++) {
if (document.getElementById("chk" + i).checked) {
bFlag = true;
}
}
if (!bFlag) {
alert("you haven't checked anything");
return false;
} else {
var oForm = document.SurveySubmitted;//change to real name
oForm.submit();
}
}
Jun 13 '06 #4

P: n/a
Thanks for accomodating Ben,

I have implemented the code without errors but it is not doing
anything. Here is my HTM source code and it looks fine.

<form action="testSubmission.asp?Survey=" 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" Name="Question1" Value="a">Dispatch
Newsletter<br>
<input type="checkbox" id="chk1" Name="Question1" Value="b">General
Notifications(email)<br>
<input type="checkbox" id="chk1" Name="Question1" Value="c">Intranet
Homepage (InSite)<br>
<input type="checkbox" id="chk1" Name="Question1" Value="d">IT Service
Desk Corporate Notifications<br>
<input type="checkbox" id="chk1" Name="Question1" Value="e">Team
Websites (http://go/it, http://go/cso etc.)<br>
<BR>Other<BR><textarea name="textBoxAnswer1" rows="2"
cols="50"></textarea>
<input type="hidden" name="HiddenTextValue" value="f">
<input type="hidden" id="CheckboxCount" value="1"><p><b>2. Please
select the 3 most helpful means of communication?</b><p>
<input type="checkbox" id="chk2" Name="Question2" Value="a">Online
Newsletter<br>
<input type="checkbox" id="chk2" Name="Question2" Value="b">Print
Newsletter<br>
<input type="checkbox" id="chk2" Name="Question2" Value="c">Intranet
homepage (Insite)<br>
<input type="hidden" id="CheckboxCount" value="2"><p><b>3. Please
select the three least helpful means of communication</b><p>
<input type="hidden" id="CheckboxCount" value="2"><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>
<input type="hidden" id="CheckboxCount" value="2"><p>
<hr>
</TABLE>
<TABLE>
<TR>
<TD COLSPAN=3 ALIGN="center"><BR>
<input type=submit value="Submit" ONCLICK="validateCheckBoxes();">

</TD>
</TR>
</TABLE>
</FORM>
</CENTER>


Ben Amada wrote:
cl********@hotmail.com wrote:
Ben Amada wrote:

Hi. Here's a pretty decent approach:

1. Assign each checkbox a unique ID using sequential numbers (chk1, chk2
... chk7). In your ASP code, you can do this by creating an integer
variable you increment by 1 each time you output a checkbox control.

2. Store the largest sequential number in a hidden field (for example,
7).

3. In validation routine, use a "for" loop -- looping from 1 thru 7 --
checking the status of each checkbox.

Ben


Hi Ben,

I'm going to have to say I don't understand. I do not wish to change
the structure since everything is working fine up until this point.
Could you clarify your point with some code. Sorry.


The code below is untested, but should get you close to what you're looking
for with few changes to what you've already got:

=== ASP code ===

Dim iCheckboxID As Integer
iCheckboxID = 0

While Not objRS.EOF

iCheckboxID = iCheckboxID + 1

response.write "<input type=""checkbox"" id=""" & _
"chk" & iCheckboxID & """ Name=""Question" & _
objRS("Question_ID") & """ Value=""" & _
objTxt("Sub_Text") & """>" & _
objTxt("Text") & "<br>" & chr(13)

objRS.MoveNext

End While

response.write "<input type=""hidden"" " & _
"id=""CheckboxCount"" " & _
"value=""" & iCheckboxID & """>"

=== JavaScript code ===

function validateCheckBoxes(){
var bFlag = false;
var iCheckboxCount = document.getElementById('CheckboxCount').value;
for (var i=1; i <= iCheckboxCount; i++) {
if (document.getElementById("chk" + i).checked) {
bFlag = true;
}
}
if (!bFlag) {
alert("you haven't checked anything");
return false;
} else {
var oForm = document.SurveySubmitted;//change to real name
oForm.submit();
}
}


Jun 13 '06 #5

P: n/a
Thanks for accomodating Ben,

I have implemented the code without errors but it is not doing
anything. Here is my HTM source code and it looks fine.

<form action="testSubmission.asp?Survey=" 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" Name="Question1" Value="a">Dispatch
Newsletter<br>
<input type="checkbox" id="chk1" Name="Question1" Value="b">General
Notifications(email)<br>
<input type="checkbox" id="chk1" Name="Question1" Value="c">Intranet
Homepage (InSite)<br>
<input type="checkbox" id="chk1" Name="Question1" Value="d">IT Service
Desk Corporate Notifications<br>
<input type="checkbox" id="chk1" Name="Question1" Value="e">Team
Websites (http://go/it, http://go/cso etc.)<br>
<BR>Other<BR><textarea name="textBoxAnswer1" rows="2"
cols="50"></textarea>
<input type="hidden" name="HiddenTextValue" value="f">
<input type="hidden" id="CheckboxCount" value="1"><p><b>2. Please
select the 3 most helpful means of communication?</b><p>
<input type="checkbox" id="chk2" Name="Question2" Value="a">Online
Newsletter<br>
<input type="checkbox" id="chk2" Name="Question2" Value="b">Print
Newsletter<br>
<input type="checkbox" id="chk2" Name="Question2" Value="c">Intranet
homepage (Insite)<br>
<input type="hidden" id="CheckboxCount" value="2"><p><b>3. Please
select the three least helpful means of communication</b><p>
<input type="hidden" id="CheckboxCount" value="2"><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>
<input type="hidden" id="CheckboxCount" value="2"><p>
<hr>
</TABLE>
<TABLE>
<TR>
<TD COLSPAN=3 ALIGN="center"><BR>
<input type=submit value="Submit" ONCLICK="validateCheckBoxes();">

</TD>
</TR>
</TABLE>
</FORM>
</CENTER>


Ben Amada wrote:
cl********@hotmail.com wrote:
Ben Amada wrote:

Hi. Here's a pretty decent approach:

1. Assign each checkbox a unique ID using sequential numbers (chk1, chk2
... chk7). In your ASP code, you can do this by creating an integer
variable you increment by 1 each time you output a checkbox control.

2. Store the largest sequential number in a hidden field (for example,
7).

3. In validation routine, use a "for" loop -- looping from 1 thru 7 --
checking the status of each checkbox.

Ben


Hi Ben,

I'm going to have to say I don't understand. I do not wish to change
the structure since everything is working fine up until this point.
Could you clarify your point with some code. Sorry.


The code below is untested, but should get you close to what you're looking
for with few changes to what you've already got:

=== ASP code ===

Dim iCheckboxID As Integer
iCheckboxID = 0

While Not objRS.EOF

iCheckboxID = iCheckboxID + 1

response.write "<input type=""checkbox"" id=""" & _
"chk" & iCheckboxID & """ Name=""Question" & _
objRS("Question_ID") & """ Value=""" & _
objTxt("Sub_Text") & """>" & _
objTxt("Text") & "<br>" & chr(13)

objRS.MoveNext

End While

response.write "<input type=""hidden"" " & _
"id=""CheckboxCount"" " & _
"value=""" & iCheckboxID & """>"

=== JavaScript code ===

function validateCheckBoxes(){
var bFlag = false;
var iCheckboxCount = document.getElementById('CheckboxCount').value;
for (var i=1; i <= iCheckboxCount; i++) {
if (document.getElementById("chk" + i).checked) {
bFlag = true;
}
}
if (!bFlag) {
alert("you haven't checked anything");
return false;
} else {
var oForm = document.SurveySubmitted;//change to real name
oForm.submit();
}
}


Jun 13 '06 #6

P: n/a
cl********@hotmail.com wrote:
Thanks for accomodating Ben,

I have implemented the code without errors but it is not doing
anything. Here is my HTM source code and it looks fine.


Thanks for posting the outputted HTML. I now see a couple of problems ...

(1) Each checkbox should have a unique "id".

(2) However, there is another problem in that I initially didn't realize you
have different sets of questions where (I'm guessing) at least one box must
be checked for each set of questions.

(3) Each checkbox 'input' tag should have a closing tag -- </input>.

--- RECOMMENDATIONS ---

(1) Use the following checkbox "id" scheme:

- For question 1's checkbox IDs, use "chk1_1", "chk1_2", "chk1_3", etc.
- For question 2's checkbox IDs, use "chk2_1", "chk2_2", "chk2_3", etc.

(2) Create one hidden input field for each set of questions:

- For question 1, create hidden input field "cbCount1" with a value
containing the number of checkboxes under question 1.
- For question 2, create hidden input field "cbCount2" with a value
containing the number of checkboxes under question 2.
etc.

(3) Create one hidden input field (QuestionCount) which contains the number
of questions you have on the page.

---------
If you follow the above 3 recommendations, then the JavaScript below should
work to make sure at least one box has been checked for each set of
questions.

=== JavaScript code Below ===

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 {
var oForm = document.SurveySubmitted;//change to real name
oForm.submit();
}

}
Jun 13 '06 #7

P: n/a
O.k Ben you know what I'm gonna ask you next right?
Well I'm not very good working with Dynamic data. Could you provide
some coe for the recommendation. Obviously that is not right of me to
ask but when I see something I understand it more thoroughly for the
next time. I'm not gonna lie I'm not sure how to complete what you
asked. Sure I understand the hidden field part but the rest not sure.
Anyway you can provide. Thanks again Ben.

And yes, each question should have at least one checkbox checked.
Ben Amada wrote:
cl********@hotmail.com wrote:
Thanks for accomodating Ben,

I have implemented the code without errors but it is not doing
anything. Here is my HTM source code and it looks fine.


Thanks for posting the outputted HTML. I now see a couple of problems ...

(1) Each checkbox should have a unique "id".

(2) However, there is another problem in that I initially didn't realize you
have different sets of questions where (I'm guessing) at least one box must
be checked for each set of questions.

(3) Each checkbox 'input' tag should have a closing tag -- </input>.

--- RECOMMENDATIONS ---

(1) Use the following checkbox "id" scheme:

- For question 1's checkbox IDs, use "chk1_1", "chk1_2", "chk1_3", etc.
- For question 2's checkbox IDs, use "chk2_1", "chk2_2", "chk2_3", etc.

(2) Create one hidden input field for each set of questions:

- For question 1, create hidden input field "cbCount1" with a value
containing the number of checkboxes under question 1.
- For question 2, create hidden input field "cbCount2" with a value
containing the number of checkboxes under question 2.
etc.

(3) Create one hidden input field (QuestionCount) which contains the number
of questions you have on the page.

---------
If you follow the above 3 recommendations, then the JavaScript below should
work to make sure at least one box has been checked for each set of
questions.

=== JavaScript code Below ===

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 {
var oForm = document.SurveySubmitted;//change to real name
oForm.submit();
}

}


Jun 13 '06 #8

P: n/a
cl********@hotmail.com wrote:
Well I'm not very good working with Dynamic data. Could you provide
some coe for the recommendation. Obviously that is not right of me to
ask but when I see something I understand it more thoroughly for the
next time. I'm not gonna lie I'm not sure how to complete what you
asked. Sure I understand the hidden field part but the rest not sure.
Anyway you can provide. Thanks again Ben.

And yes, each question should have at least one checkbox checked.


I believe you're asking about the ASP coding. Basically you'll want to
maintain 2 variables, iQuestionID and iCheckboxID, where iQuestionID keeps
track of the current question id and iCheckboxID keeps track of the current
checkbox id WITHIN (or FOR) the current question. Not being familiar with
the details of your code, the sample code below is just an example of what
you are probably looking for.

Dim iQuestionID As Integer
Dim iCheckboxID As Integer
Dim strCurrentQuestionID As String

While Not objRS.EOF

If objRS("Question_ID") <> strCurrentQuestionID Then

If iQuestionID > 0 Then

response.write "<input type=""hidden"" " & _
"id=""cbCount""" & iQuestionID & " " & _
"value=""" & iCheckboxID & """>"

End If

strCurrentQuestionID = objRS("Question_ID")
iQuestionID = iQuestionID + 1
iCheckboxID = 0

response.write "Question #" & iQuestionID & "<br>"

End If

iCheckboxID = iCheckboxID + 1

response.write "<input type=""checkbox"" id=""" & _
"chk" & iQuestionID & "_" & iCheckboxID & """ " & _
"Name=""Question" & _
objRS("Question_ID") & """ Value=""" & _
objTxt("Sub_Text") & """>" & _
objTxt("Text") & "</input><br>" & chr(13)

objRS.MoveNext
End While

response.write "<input type=""hidden"" " & _
"id=""QuestionCount"" " & _
"value=""" & iQuestionID & """>"
Jun 13 '06 #9

P: n/a
Ben Amada wrote:
If iQuestionID > 0 Then

response.write "<input type=""hidden"" " & _
"id=""cbCount""" & iQuestionID & " " & _
"value=""" & iCheckboxID & """>"

End If


.... oops (minor mistake), the above code should read:

If iQuestionID > 0 Then

response.write "<input type=""hidden"" " & _
"id=""cbCount" & iQuestionID & """ " & _
"value=""" & iCheckboxID & """>"

End If

----------
Good luck!
Ben
Jun 13 '06 #10

P: n/a
.... one more glitch (obviously I've just been typing air-code :) You'll
want to output one last hidden input field after the While loop is over.

....
....
End While

If iQuestionID > 0 Then
response.write "<input type=""hidden"" " & _
"id=""cbCount" & iQuestionID & """ " & _
"value=""" & iCheckboxID & """>"
End If

response.write "<input type=""hidden"" " & _
"id=""QuestionCount"" " & _
"value=""" & iQuestionID & """>"
If iQuestionID > 0 Then
Jun 13 '06 #11

P: n/a
Wow Ben,

I would had to start changing code that I worked so hard on. What if I
wanted to implement your code to my code. This is my code. Short and
sweet. Could it not be incorporated into my code

<BODY leftmargin="0" rightmargin="0" marginwidth="0" topmargin="0"
marginheight="0" bottommargin="0" bgcolor="#ffffff">
<table width="60%" cellspacing="0" cellpadding="5">
<%
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DSN"
'now find the quiz specified by the URL command line
'e.g. vbquiz.asp?quiz=1 means show quiz 1
survey=1
set objRS = oConn.Execute("SELECT * FROM Survey WHERE Survey_ID=" &
survey)
%>
<hr>
<font size=5>
<center><b><% =objRS("Descr") %></center></b>
<HR>
</font>
<p>
<form
action="testSubmission.asp?Survey=<%=request.query string("Survey") %>"
method="post" name="SurveySubmitted">
<%
objRS.close
'now start the main loop to find all the questions

set objRS = oConn.Execute("SELECT * FROM survey_questions WHERE
Survey_ID=" & survey & " ORDER BY Question_ID")

If not objRS.eof Then
%>
<input type="hidden" name="HiddenSurveyID"
value="<%=objRS("Survey_ID")%>">
<input type="hidden" name="HiddenQuestionID"
value="<%=objRS("Question_ID")%>">
<%
End IF
if not objRS.EOF then
objRS.movefirst
do
response.write "<b>" & objRS("Question_ID") & ". " &
objRS("Question") & "</b><p>" & chr(13)
'now display the available options
set objTxt = oConn.Execute("SELECT * FROM survey_user_text WHERE
Question_ID=" & objRS("Question_ID") )
if not objTxt.EOF then
objTxt.movefirst
Do
If (objTxt("Type")) = "radio" then
response.write "<input type=checkbox Name=""Question" &
objRS("Question_ID") & """ Value=""" & objTxt("Sub_Text") & """>" &
objTxt("Text") & "<br>" & chr(13)
ELSE
response.write "<BR>" & objTxt("Text")& "<BR>" %><textarea
name="textBoxAnswer<%=objRS("Question_Id")%>" rows="2"
cols="50"></textarea>
<input type="hidden" name="HiddenTextValue"
value="<%=objTxt("sub_text")%>">
<%
End IF
objTxt.movenext
loop until objTxt.EOF
end if
response.write "<p>"
objRS.movenext
loop until objRS.EOF
end if
oConn.close
%>
<hr>
</TABLE>
<TABLE>
<TR>
<TD COLSPAN=3 ALIGN="center"><BR>
<input type=submit value="Submit" ONCLICK="validateCheckBoxes();">
</TD>
</TR>
</TABLE>
</FORM>
</CENTER>
Ben Amada wrote:
... one more glitch (obviously I've just been typing air-code :) You'll
want to output one last hidden input field after the While loop is over.

...
...
End While

If iQuestionID > 0 Then
response.write "<input type=""hidden"" " & _
"id=""cbCount" & iQuestionID & """ " & _
"value=""" & iCheckboxID & """>"
End If

response.write "<input type=""hidden"" " & _
"id=""QuestionCount"" " & _
"value=""" & iQuestionID & """>"
If iQuestionID > 0 Then


Jun 13 '06 #12

P: n/a
cl********@hotmail.com wrote:
Wow Ben,

I would had to start changing code that I worked so hard on. What if I
wanted to implement your code to my code. This is my code. Short and
sweet. Could it not be incorporated into my code


Didn't mean to overwhelm you :) I was able to basically copy the ASP
code from my other post and paste it into your ASP code (see below).
It is untested as I don't have a database setup -- but should work.
The only other thing you'd want to do is insert the JavaScript I posted
a few posts ago into your code.

Good luck,
Ben
---------------------------------------------

<BODY leftmargin="0" rightmargin="0" marginwidth="0" topmargin="0"
marginheight="0" bottommargin="0" bgcolor="#ffffff">
<table width="60%" cellspacing="0" cellpadding="5">
<%
Dim iQuestionID As Integer
Dim iCheckboxID As Integer
Dim strCurrentQuestionID As String
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DSN"
'now find the quiz specified by the URL command line
'e.g. vbquiz.asp?quiz=1 means show quiz 1
survey=1
set objRS = oConn.Execute("SELECT * FROM Survey WHERE Survey_ID=" &
survey)
%>
<hr>
<font size=5>
<center><b><% =objRS("Descr") %></center></b>
<HR>
</font>
<p>
<form
action="testSubmission.asp?Survey=<%=request.query string("Survey") %>"
method="post" name="SurveySubmitted">
<%
objRS.close
'now start the main loop to find all the questions

set objRS = oConn.Execute("SELECT * FROM survey_questions WHERE
Survey_ID=" & survey & " ORDER BY Question_ID")

If not objRS.eof Then
%>
<input type="hidden" name="HiddenSurveyID"
value="<%=objRS("Survey_ID")%>">
<input type="hidden" name="HiddenQuestionID"
value="<%=objRS("Question_ID")%>">
<%
End IF
if not objRS.EOF then
objRS.movefirst
do
response.write "<b>" & objRS("Question_ID") & ". " &
objRS("Question") & "</b><p>" & chr(13)
'now display the available options
set objTxt = oConn.Execute("SELECT * FROM
survey_user_text WHERE
Question_ID=" & objRS("Question_ID") )
if not objTxt.EOF then

objTxt.movefirst
Do

If (objTxt("Type")) = "radio" then

If objRS("Question_ID") <> strCurrentQuestionID Then

If iQuestionID > 0 Then
response.write "<input type=""hidden"" " & _
"id=""cbCount" & iQuestionID & """ " & _
"value=""" & iCheckboxID & """>"
End If

strCurrentQuestionID = objRS("Question_ID")
iQuestionID = iQuestionID + 1
iCheckboxID = 0

'response.write "Question #" & iQuestionID & "<br>"

End If

iCheckboxID = iCheckboxID + 1

response.write "<input type=""checkbox"" id=""" & _
"chk" & iQuestionID & "_" & iCheckboxID & """ " & _
"Name=""Question" & _
objRS("Question_ID") & """ Value=""" & _
objTxt("Sub_Text") & """>" & _
objTxt("Text") & "</input><br>" & chr(13)

ELSE
response.write "<BR>" & objTxt("Text")& "<BR>" %><textarea
name="textBoxAnswer<%=objRS("Question_Id")%>" rows="2"
cols="50"></textarea>
<input type="hidden" name="HiddenTextValue"
value="<%=objTxt("sub_text")%>">
<%
End IF
objTxt.movenext
loop until objTxt.EOF

end if
response.write "<p>"
objRS.movenext
loop until objRS.EOF

If iQuestionID > 0 Then
response.write "<input type=""hidden"" " & _
"id=""cbCount" & iQuestionID & """ " & _
"value=""" & iCheckboxID & """>"
End If

response.write "<input type=""hidden"" " & _
"id=""QuestionCount"" " & _
"value=""" & iQuestionID & """>"

end if
oConn.close
%>
<hr>
</TABLE>
<TABLE>
<TR>
<TD COLSPAN=3 ALIGN="center"><BR>
<input type=submit value="Submit"
ONCLICK="validateCheckBoxes();">
</TD>
</TR>
</TABLE>
</FORM>
</CENTER>

Jun 14 '06 #13

P: n/a
Hello again Ben and I really appreciate this.
I am getting a Type Mismatch error with respect to this line

If objRS("Question_ID") <> strCurrentQuestionID Then

Also, I did not declare a type for the following variables since you do
not have to in asp and secondly it gives me an error. I think this is
the cause of the type mismatch. Any ideas?

Dim iQuestionID As Integer
Dim iCheckboxID As Integer
Dim strCurrentQuestionID As String


Ben Amada wrote:
cl********@hotmail.com wrote:
Wow Ben,

I would had to start changing code that I worked so hard on. What if I
wanted to implement your code to my code. This is my code. Short and
sweet. Could it not be incorporated into my code


Didn't mean to overwhelm you :) I was able to basically copy the ASP
code from my other post and paste it into your ASP code (see below).
It is untested as I don't have a database setup -- but should work.
The only other thing you'd want to do is insert the JavaScript I posted
a few posts ago into your code.

Good luck,
Ben
---------------------------------------------

<BODY leftmargin="0" rightmargin="0" marginwidth="0" topmargin="0"
marginheight="0" bottommargin="0" bgcolor="#ffffff">
<table width="60%" cellspacing="0" cellpadding="5">
<%
Dim iQuestionID As Integer
Dim iCheckboxID As Integer
Dim strCurrentQuestionID As String
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DSN"
'now find the quiz specified by the URL command line
'e.g. vbquiz.asp?quiz=1 means show quiz 1
survey=1
set objRS = oConn.Execute("SELECT * FROM Survey WHERE Survey_ID=" &
survey)
%>
<hr>
<font size=5>
<center><b><% =objRS("Descr") %></center></b>
<HR>
</font>
<p>
<form
action="testSubmission.asp?Survey=<%=request.query string("Survey") %>"
method="post" name="SurveySubmitted">
<%
objRS.close
'now start the main loop to find all the questions

set objRS = oConn.Execute("SELECT * FROM survey_questions WHERE
Survey_ID=" & survey & " ORDER BY Question_ID")

If not objRS.eof Then
%>
<input type="hidden" name="HiddenSurveyID"
value="<%=objRS("Survey_ID")%>">
<input type="hidden" name="HiddenQuestionID"
value="<%=objRS("Question_ID")%>">
<%
End IF
if not objRS.EOF then
objRS.movefirst
do
response.write "<b>" & objRS("Question_ID") & ". " &
objRS("Question") & "</b><p>" & chr(13)
'now display the available options
set objTxt = oConn.Execute("SELECT * FROM
survey_user_text WHERE
Question_ID=" & objRS("Question_ID") )
if not objTxt.EOF then

objTxt.movefirst
Do

If (objTxt("Type")) = "radio" then

If objRS("Question_ID") <> strCurrentQuestionID Then

If iQuestionID > 0 Then
response.write "<input type=""hidden"" " & _
"id=""cbCount" & iQuestionID & """ " & _
"value=""" & iCheckboxID & """>"
End If

strCurrentQuestionID = objRS("Question_ID")
iQuestionID = iQuestionID + 1
iCheckboxID = 0

'response.write "Question #" & iQuestionID & "<br>"

End If

iCheckboxID = iCheckboxID + 1

response.write "<input type=""checkbox"" id=""" & _
"chk" & iQuestionID & "_" & iCheckboxID & """ " & _
"Name=""Question" & _
objRS("Question_ID") & """ Value=""" & _
objTxt("Sub_Text") & """>" & _
objTxt("Text") & "</input><br>" & chr(13)

ELSE
response.write "<BR>" & objTxt("Text")& "<BR>" %><textarea
name="textBoxAnswer<%=objRS("Question_Id")%>" rows="2"
cols="50"></textarea>
<input type="hidden" name="HiddenTextValue"
value="<%=objTxt("sub_text")%>">
<%
End IF
objTxt.movenext
loop until objTxt.EOF

end if
response.write "<p>"
objRS.movenext
loop until objRS.EOF

If iQuestionID > 0 Then
response.write "<input type=""hidden"" " & _
"id=""cbCount" & iQuestionID & """ " & _
"value=""" & iCheckboxID & """>"
End If

response.write "<input type=""hidden"" " & _
"id=""QuestionCount"" " & _
"value=""" & iQuestionID & """>"

end if
oConn.close
%>
<hr>
</TABLE>
<TABLE>
<TR>
<TD COLSPAN=3 ALIGN="center"><BR>
<input type=submit value="Submit"
ONCLICK="validateCheckBoxes();">
</TD>
</TR>
</TABLE>
</FORM>
</CENTER>


Jun 14 '06 #14

P: n/a
Hello again Ben and I really appreciate this.
I am getting a Type Mismatch error with respect to this line

If objRS("Question_ID") <> strCurrentQuestionID Then

Also, I did not declare a type for the following variables since you do
not have to in asp and secondly it gives me an error. I think this is
the cause of the type mismatch. Any ideas?

Dim iQuestionID As Integer
Dim iCheckboxID As Integer
Dim strCurrentQuestionID As String


Ben Amada wrote:
cl********@hotmail.com wrote:
Wow Ben,

I would had to start changing code that I worked so hard on. What if I
wanted to implement your code to my code. This is my code. Short and
sweet. Could it not be incorporated into my code


Didn't mean to overwhelm you :) I was able to basically copy the ASP
code from my other post and paste it into your ASP code (see below).
It is untested as I don't have a database setup -- but should work.
The only other thing you'd want to do is insert the JavaScript I posted
a few posts ago into your code.

Good luck,
Ben
---------------------------------------------

<BODY leftmargin="0" rightmargin="0" marginwidth="0" topmargin="0"
marginheight="0" bottommargin="0" bgcolor="#ffffff">
<table width="60%" cellspacing="0" cellpadding="5">
<%
Dim iQuestionID As Integer
Dim iCheckboxID As Integer
Dim strCurrentQuestionID As String
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DSN"
'now find the quiz specified by the URL command line
'e.g. vbquiz.asp?quiz=1 means show quiz 1
survey=1
set objRS = oConn.Execute("SELECT * FROM Survey WHERE Survey_ID=" &
survey)
%>
<hr>
<font size=5>
<center><b><% =objRS("Descr") %></center></b>
<HR>
</font>
<p>
<form
action="testSubmission.asp?Survey=<%=request.query string("Survey") %>"
method="post" name="SurveySubmitted">
<%
objRS.close
'now start the main loop to find all the questions

set objRS = oConn.Execute("SELECT * FROM survey_questions WHERE
Survey_ID=" & survey & " ORDER BY Question_ID")

If not objRS.eof Then
%>
<input type="hidden" name="HiddenSurveyID"
value="<%=objRS("Survey_ID")%>">
<input type="hidden" name="HiddenQuestionID"
value="<%=objRS("Question_ID")%>">
<%
End IF
if not objRS.EOF then
objRS.movefirst
do
response.write "<b>" & objRS("Question_ID") & ". " &
objRS("Question") & "</b><p>" & chr(13)
'now display the available options
set objTxt = oConn.Execute("SELECT * FROM
survey_user_text WHERE
Question_ID=" & objRS("Question_ID") )
if not objTxt.EOF then

objTxt.movefirst
Do

If (objTxt("Type")) = "radio" then

If objRS("Question_ID") <> strCurrentQuestionID Then

If iQuestionID > 0 Then
response.write "<input type=""hidden"" " & _
"id=""cbCount" & iQuestionID & """ " & _
"value=""" & iCheckboxID & """>"
End If

strCurrentQuestionID = objRS("Question_ID")
iQuestionID = iQuestionID + 1
iCheckboxID = 0

'response.write "Question #" & iQuestionID & "<br>"

End If

iCheckboxID = iCheckboxID + 1

response.write "<input type=""checkbox"" id=""" & _
"chk" & iQuestionID & "_" & iCheckboxID & """ " & _
"Name=""Question" & _
objRS("Question_ID") & """ Value=""" & _
objTxt("Sub_Text") & """>" & _
objTxt("Text") & "</input><br>" & chr(13)

ELSE
response.write "<BR>" & objTxt("Text")& "<BR>" %><textarea
name="textBoxAnswer<%=objRS("Question_Id")%>" rows="2"
cols="50"></textarea>
<input type="hidden" name="HiddenTextValue"
value="<%=objTxt("sub_text")%>">
<%
End IF
objTxt.movenext
loop until objTxt.EOF

end if
response.write "<p>"
objRS.movenext
loop until objRS.EOF

If iQuestionID > 0 Then
response.write "<input type=""hidden"" " & _
"id=""cbCount" & iQuestionID & """ " & _
"value=""" & iCheckboxID & """>"
End If

response.write "<input type=""hidden"" " & _
"id=""QuestionCount"" " & _
"value=""" & iQuestionID & """>"

end if
oConn.close
%>
<hr>
</TABLE>
<TABLE>
<TR>
<TD COLSPAN=3 ALIGN="center"><BR>
<input type=submit value="Submit"
ONCLICK="validateCheckBoxes();">
</TD>
</TR>
</TABLE>
</FORM>
</CENTER>


Jun 14 '06 #15

P: n/a

cl********@hotmail.com wrote:
Hello again Ben and I really appreciate this.
I am getting a Type Mismatch error with respect to this line

If objRS("Question_ID") <> strCurrentQuestionID Then

Also, I did not declare a type for the following variables since you do
not have to in asp and secondly it gives me an error. I think this is
the cause of the type mismatch. Any ideas?


Classic ASP uses VBscript, which doesn't declare variable types as you
noted, but it does have typed variables. Generally everything is of
type "variant" but often stuff coming back from a database has explicit
types set that give you typemismatch errors.

If the ID is an integer, then you'll need to convert it to a longint
first - clng(objRS("Question_ID")). However that will crash if for some
reason the Question ID is null, so check that first.

<form
action="testSubmission.asp?Survey=<%=request.query string("Survey") %>"
method="post" name="SurveySubmitted">


Never, ever, ever, ever do this.

You are outputting the querystring straight back to the client. This
lets someone insert any code they like into your page. Always read
querystring parameters into a local variable, check its content and the
write that back to the client. If you are expecting an integer, check
that it is one and is in range, otherwise produce an error or use a
default value.

Jun 14 '06 #16

P: n/a
O.k.

Well I added what you said Ben and still no good. The value being
returned is a number. Question_id is the question Number. So I added
If CLng(objRS("Question_ID") <> strCurrentQuestionID Then

and still getting the errors. I also remarked the line completely just
to troubleshoot and see what is going on and the page came up. However
if I click submit i get
a non-numeric character was found where a numeric was expected
/itsurvey/testSubmission.asp, line 64

ne**@chthonic.f9.co.uk wrote:
cl********@hotmail.com wrote:
Hello again Ben and I really appreciate this.
I am getting a Type Mismatch error with respect to this line

If objRS("Question_ID") <> strCurrentQuestionID Then

Also, I did not declare a type for the following variables since you do
not have to in asp and secondly it gives me an error. I think this is
the cause of the type mismatch. Any ideas?


Classic ASP uses VBscript, which doesn't declare variable types as you
noted, but it does have typed variables. Generally everything is of
type "variant" but often stuff coming back from a database has explicit
types set that give you typemismatch errors.

If the ID is an integer, then you'll need to convert it to a longint
first - clng(objRS("Question_ID")). However that will crash if for some
reason the Question ID is null, so check that first.

<form
action="testSubmission.asp?Survey=<%=request.query string("Survey") %>"
method="post" name="SurveySubmitted">


Never, ever, ever, ever do this.

You are outputting the querystring straight back to the client. This
lets someone insert any code they like into your page. Always read
querystring parameters into a local variable, check its content and the
write that back to the client. If you are expecting an integer, check
that it is one and is in range, otherwise produce an error or use a
default value.


Jun 14 '06 #17

P: n/a
cl********@hotmail.com wrote:
Hello again Ben and I really appreciate this.
I am getting a Type Mismatch error with respect to this line

If objRS("Question_ID") <> strCurrentQuestionID Then

Also, I did not declare a type for the following variables since you do
not have to in asp and secondly it gives me an error. I think this is
the cause of the type mismatch. Any ideas?

Dim iQuestionID As Integer
Dim iCheckboxID As Integer
Dim strCurrentQuestionID As String


Okay ... I would drop the 'type' of the variables and give each variable a
default value. So replace the 3 variable declaration lines above with:

Dim iQuestionID
Dim iCheckboxID
Dim strCurrentQuestionID
iQuestionID = 0
iCheckboxID = 0
strCurrentQuestionID = 0

This assumes objRS("Question_ID") is a numeric value.

Ben
Jun 14 '06 #18

P: n/a
Nope still no go.

Here is my table structure

"Column Name""Data Type""
"SURVEY_ID""NUMBER"
"QUESTION_ID""NUMBER"
"QUESTION""VARCHAR2(4000 Bytes)"
"TYPE" "VARCHAR2(4000 Bytes)" ""


Ben Amada wrote:
cl********@hotmail.com wrote:
Hello again Ben and I really appreciate this.
I am getting a Type Mismatch error with respect to this line

If objRS("Question_ID") <> strCurrentQuestionID Then

Also, I did not declare a type for the following variables since you do
not have to in asp and secondly it gives me an error. I think this is
the cause of the type mismatch. Any ideas?

Dim iQuestionID As Integer
Dim iCheckboxID As Integer
Dim strCurrentQuestionID As String


Okay ... I would drop the 'type' of the variables and give each variable a
default value. So replace the 3 variable declaration lines above with:

Dim iQuestionID
Dim iCheckboxID
Dim strCurrentQuestionID
iQuestionID = 0
iCheckboxID = 0
strCurrentQuestionID = 0

This assumes objRS("Question_ID") is a numeric value.

Ben


Jun 14 '06 #19

P: n/a
cl********@hotmail.com wrote:
Nope still no go.

Here is my table structure

"Column Name""Data Type""
"SURVEY_ID""NUMBER"
"QUESTION_ID""NUMBER"
"QUESTION""VARCHAR2(4000 Bytes)"
"TYPE" "VARCHAR2(4000 Bytes)" ""


Hmm... what error are you getting now? By the way, since
strCurrentQuestionID is now initialized with a numeric value, you should be
able to use the following line of code:

If objRS("Question_ID") <> strCurrentQuestionID Then

So you don't need the CLng() function since both objRS("Question_ID") and
strCurrentQuestionID are numeric.

Ben
Jun 14 '06 #20

P: n/a
Correct Ben, yes I was aware that I did not need the clng function and
it was removed so only If objRS("Question_ID") <> strCurrentQuestionID
Then shows.

The error I am receiving is the same just different line number because
the variable lines shifted the code lines

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
/itsurvey/samtestingben.asp, line 56
Ben Amada wrote:
cl********@hotmail.com wrote:
Nope still no go.

Here is my table structure

"Column Name""Data Type""
"SURVEY_ID""NUMBER"
"QUESTION_ID""NUMBER"
"QUESTION""VARCHAR2(4000 Bytes)"
"TYPE" "VARCHAR2(4000 Bytes)" ""


Hmm... what error are you getting now? By the way, since
strCurrentQuestionID is now initialized with a numeric value, you should be
able to use the following line of code:

If objRS("Question_ID") <> strCurrentQuestionID Then

So you don't need the CLng() function since both objRS("Question_ID") and
strCurrentQuestionID are numeric.

Ben


Jun 14 '06 #21

P: n/a
Correct Ben, yes I was aware that I did not need the clng function and
it was removed so only If objRS("Question_ID") <> strCurrentQuestionID
Then shows.

The error I am receiving is the same just different line number because
the variable lines shifted the code lines

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
/itsurvey/samtestingben.asp, line 56
Ben Amada wrote:
cl********@hotmail.com wrote:
Nope still no go.

Here is my table structure

"Column Name""Data Type""
"SURVEY_ID""NUMBER"
"QUESTION_ID""NUMBER"
"QUESTION""VARCHAR2(4000 Bytes)"
"TYPE" "VARCHAR2(4000 Bytes)" ""


Hmm... what error are you getting now? By the way, since
strCurrentQuestionID is now initialized with a numeric value, you should be
able to use the following line of code:

If objRS("Question_ID") <> strCurrentQuestionID Then

So you don't need the CLng() function since both objRS("Question_ID") and
strCurrentQuestionID are numeric.

Ben


Jun 14 '06 #22

P: n/a
cl********@hotmail.com wrote:
Correct Ben, yes I was aware that I did not need the clng function and
it was removed so only If objRS("Question_ID") <> strCurrentQuestionID
Then shows.

The error I am receiving is the same just different line number because
the variable lines shifted the code lines

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
/itsurvey/samtestingben.asp, line 56


Is line 56 the <If objRS("Question_ID") <> strCurrentQuestionID Then> line?

You do have the <strCurrentQuestionID = 0> line in there after the variable
declaration at the top?

Maybe you can post your ASP code again (the entire thing).

Ben
Jun 14 '06 #23

P: n/a
yes line 56 is the <If objRS("Question_ID") <> strCurrentQuestionID
Then> line
<BODY leftmargin="0" rightmargin="0" marginwidth="0" topmargin="0"
marginheight="0" bottommargin="0" bgcolor="#ffffff">
<table width="60%" cellspacing="0" cellpadding="5">
<%
Dim iQuestionID
Dim iCheckboxID
Dim strCurrentQuestionID
iQuestionID = 0
iCheckboxID = 0
strCurrentQuestionID = 0

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DSN=Oracle;uid=rpt_user;pwd=rpt#user;"
'now find the quiz specified by the URL command line
'e.g. vbquiz.asp?quiz=1 means show quiz 1
survey=1
set objRS = oConn.Execute("SELECT * FROM Survey WHERE Survey_ID=" &
survey)
%>
<hr>
<font size=5>
<center><b><% =objRS("Descr") %></center></b>
<HR>
</font>
<p>
<form action="testSubmission.asp" method="post" name="SurveySubmitted">

<%
objRS.close
'now start the main loop to find all the questions

set objRS = oConn.Execute("SELECT * FROM survey_questions WHERE
Survey_ID=" & survey & " ORDER BY Question_ID")

If not objRS.eof Then
%>
<input type="hidden" name="HiddenSurveyID"
value="<%=objRS("Survey_ID")%>">
<input type="hidden" name="HiddenQuestionID"
value="<%=objRS("Question_ID")%>">
<%
End IF

if not objRS.EOF then
objRS.movefirst
do
response.write "<b>" & objRS("Question_ID") & ". " &
objRS("Question") & "</b><p>" & chr(13)
'now display the available options
set objTxt = oConn.Execute("SELECT * FROM survey_user_text WHERE
Question_ID=" & objRS("Question_ID"))
if not objTxt.EOF then
objTxt.movefirst
do

If (objTxt("Type")) = "radio" then

If objRS("Question_ID") <> strCurrentQuestionID Then

If iQuestionID > 0 Then
response.write "<input type=""hidden"" " & "id=""cbCount" &
iQuestionID & """ " & "value=""" & iCheckboxID & """>"
End If

strCurrentQuestionID = objRS("Question_ID")
iQuestionID = iQuestionID + 1
iCheckboxID = 0

'response.write "Question #" & iQuestionID & "<br>"
End If

iCheckboxID = iCheckboxID + 1

response.write "<input type=""checkbox"" id=""" & "chk" & iQuestionID
& "_" & iCheckboxID & """ " & "Name=""Question" & objRS("Question_ID")
& """ Value=""" & objTxt("Sub_Text") & """>" & objTxt("Text") &
"</input><br>" & chr(13)

ELSE
response.write "<BR>" & objTxt("Text")& "<BR>" %><textarea
name="textBoxAnswer<%=objRS("Question_Id")%>" rows="2"
cols="50"></textarea>
<input type="hidden" name="HiddenTextValue"
value="<%=objTxt("sub_text")%>">
<%
End IF
objTxt.movenext
loop until objTxt.EOF
end if
response.write "<p>"
objRS.movenext
loop until objRS.EOF

If iQuestionID > 0 Then
response.write "<input type=""hidden"" " & "id=""cbCount" &
iQuestionID & """ " & "value=""" & iCheckboxID & """>"
End If
response.write "<input type=""hidden"" " & "id=""QuestionCount"" " &
"value=""" & iQuestionID & """>"
End if
oConn.close
%>
<hr>
</TABLE>
<TABLE>
<TR>
<TD COLSPAN=3 ALIGN="center"><BR>
<input type=submit value="Submit" ONCLICK="validateCheckBoxes();">
</TD>
</TR>
</TABLE>
</FORM>
</CENTER>
Ben Amada wrote:
cl********@hotmail.com wrote:
Correct Ben, yes I was aware that I did not need the clng function and
it was removed so only If objRS("Question_ID") <> strCurrentQuestionID
Then shows.

The error I am receiving is the same just different line number because
the variable lines shifted the code lines

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
/itsurvey/samtestingben.asp, line 56


Is line 56 the <If objRS("Question_ID") <> strCurrentQuestionID Then> line?

You do have the <strCurrentQuestionID = 0> line in there after the variable
declaration at the top?

Maybe you can post your ASP code again (the entire thing).

Ben


Jun 14 '06 #24

P: n/a
cl********@hotmail.com wrote:
yes line 56 is the <If objRS("Question_ID") <> strCurrentQuestionID
Then> line


Unfortunately at this point, nothing obvious stands out to me. However,
here's something to try:

Replace ...
strCurrentQuestionID = 0
.... with ...
strCurrentQuestionID = ""
.... then change ...
If objRS("Question_ID") <> strCurrentQuestionID Then
.... to ...
If CStr(objRS("Question_ID")) <> CStr(strCurrentQuestionID) Then
.... then change ...
strCurrentQuestionID = objRS("Question_ID")
.... to ...
strCurrentQuestionID = CStr(objRS("Question_ID"))

This will force all of these statements to be evaluated as Strings which
should avoid the type mismatch errors.

Ben
Jun 14 '06 #25

P: n/a
O.K Ben I have made the changes and I no longer get the error. Any
ideas why the error with the numeric.

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?
Ben Amada wrote:
cl********@hotmail.com wrote:
yes line 56 is the <If objRS("Question_ID") <> strCurrentQuestionID
Then> line


Unfortunately at this point, nothing obvious stands out to me. However,
here's something to try:

Replace ...
strCurrentQuestionID = 0
... with ...
strCurrentQuestionID = ""
... then change ...
If objRS("Question_ID") <> strCurrentQuestionID Then
... to ...
If CStr(objRS("Question_ID")) <> CStr(strCurrentQuestionID) Then
... then change ...
strCurrentQuestionID = objRS("Question_ID")
... to ...
strCurrentQuestionID = CStr(objRS("Question_ID"))

This will force all of these statements to be evaluated as Strings which
should avoid the type mismatch errors.

Ben


Jun 14 '06 #26

P: n/a
I made the changes and it worked however no ideas on why it would not
work with the correct numeric type.

Also, I added the javascript function and it doesn;t appear to work.
It prompts the user with the specified error if he/she both has not
checked anything and has checked something. It also continues to my
thankyou.asp page with having the user first adding checks to the
answers.


Ben Amada wrote:
cl********@hotmail.com wrote:
yes line 56 is the <If objRS("Question_ID") <> strCurrentQuestionID
Then> line


Unfortunately at this point, nothing obvious stands out to me. However,
here's something to try:

Replace ...
strCurrentQuestionID = 0
... with ...
strCurrentQuestionID = ""
... then change ...
If objRS("Question_ID") <> strCurrentQuestionID Then
... to ...
If CStr(objRS("Question_ID")) <> CStr(strCurrentQuestionID) Then
... then change ...
strCurrentQuestionID = objRS("Question_ID")
... to ...
strCurrentQuestionID = CStr(objRS("Question_ID"))

This will force all of these statements to be evaluated as Strings which
should avoid the type mismatch errors.

Ben


Jun 14 '06 #27

P: n/a
cl********@hotmail.com wrote:
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
Jun 14 '06 #28

P: n/a
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 Amada wrote:
cl********@hotmail.com wrote:
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


Jun 14 '06 #29

P: n/a
cl********@hotmail.com wrote:
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.
<TABLE>
<TR>
<TD COLSPAN=3 ALIGN="center"><BR>
<input type=submit value="Submit" ONCLICK="return
validateCheckBoxes();">
</TD>
</TR>
</TABLE>


After a quick test here, it appears that the line break in the submit
input tag is causing problems. Make sure the following line of code is
all on one line without any line breaks:

<input type=submit value="Submit" ONCLICK="return
validateCheckBoxes();">

Otherwise, everything looks good and runs correctly when testing on my
side.

You might also want to add a closing </body> and </html> tag to the end
of your document. Currently, the HTML just ends with a </center> tag.

Let me know if the above correction doesn't fix the problem.

Ben

Jun 14 '06 #30

P: n/a
Hey Ben,

My submit was on one line and that was not causing the problems. What
I did notice is that if I put a checkmark in every single answer for
each question it will submit. All I want from our original discussion
was that the user needs to just select one answer for each question
before a submission occurs.
Ben Amada wrote:
cl********@hotmail.com wrote:
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.
<TABLE>
<TR>
<TD COLSPAN=3 ALIGN="center"><BR>
<input type=submit value="Submit" ONCLICK="return
validateCheckBoxes();">
</TD>
</TR>
</TABLE>


After a quick test here, it appears that the line break in the submit
input tag is causing problems. Make sure the following line of code is
all on one line without any line breaks:

<input type=submit value="Submit" ONCLICK="return
validateCheckBoxes();">

Otherwise, everything looks good and runs correctly when testing on my
side.

You might also want to add a closing </body> and </html> tag to the end
of your document. Currently, the HTML just ends with a </center> tag.

Let me know if the above correction doesn't fix the problem.

Ben


Jun 14 '06 #31

P: n/a
cl********@hotmail.com wrote:
Hey Ben,

My submit was on one line and that was not causing the problems. What
I did notice is that if I put a checkmark in every single answer for
each question it will submit. All I want from our original discussion
was that the user needs to just select one answer for each question
before a submission occurs.


Actually, the JavaScript should do exactly what you are saying. Over
here, all I need to do is check one box for each question for the form
to submit. I'm wondering if some JavaScript error is occurring on your
end. Which browser/version are you using? I'm running IE6 on Windows
XP SP2.

Below is an updated version of the JavaScript that includes some
message boxes for debugging purposes. Try running the page with this
JavaScript to see if you get any message box alerts.

Ben

-----------------------

function validateCheckBoxes(){

var bOK = true;
var bFlag = false;
var iCheckboxCount = 0;
var iCheckCount = 0;
var iQuestionCount = document.getElementById('QuestionCount').value;

alert("Total number of checkbox questions = " + iQuestionCount);

for (var i=1; i <= iQuestionCount; i++) {
bFlag = false;
iCheckboxCount = document.getElementById('cbCount' + i).value;
iCheckCount = 0;

for (var j=1; j <= iCheckboxCount; j++) {
if (document.getElementById("chk" + i + "_" + j).checked) {
iCheckCount += 1;
bFlag = true;
}
}

alert("Number " + i + ", " + iCheckCount + " out of " +
iCheckboxCount + " are checked.");

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();
}

}

Jun 14 '06 #32

P: n/a
O.k now we are talking. Not sure what the difference was but now it is
working.

Ben can I ask you one final question since you are a genious. Do you
know how to insert date time into an oracle database. What I mean is
how would I get the current date time when the user submits the form to
the database. Here is my sql insert that does work for all the other
parameters but not for date time. I also think there is something
wrong with my double and single quotes but I cannot see it. The
following works to add date but not time. How do I get datetime into
an oracle database. Thanks again for all your help.

CurDate = year(date) & left("00",2-len(month(date))) & month(date) &
left("00",2-len(day(date))) & day(date)

ssqlCheckBox = "INSERT INTO
Survey_User_Answer(Survey_Id,Question_Id,Answer_Id ,Date_Answer,User_ID)
VALUES (" & SurveyID & ",'" & objRS("Question_Id") & "' , '" &
answerChoices(answerChoice) & "' , TO_DATE("&CurDate&"), 'user')"
Ben Amada wrote:
cl********@hotmail.com wrote:
Hey Ben,

My submit was on one line and that was not causing the problems. What
I did notice is that if I put a checkmark in every single answer for
each question it will submit. All I want from our original discussion
was that the user needs to just select one answer for each question
before a submission occurs.


Actually, the JavaScript should do exactly what you are saying. Over
here, all I need to do is check one box for each question for the form
to submit. I'm wondering if some JavaScript error is occurring on your
end. Which browser/version are you using? I'm running IE6 on Windows
XP SP2.

Below is an updated version of the JavaScript that includes some
message boxes for debugging purposes. Try running the page with this
JavaScript to see if you get any message box alerts.

Ben

-----------------------

function validateCheckBoxes(){

var bOK = true;
var bFlag = false;
var iCheckboxCount = 0;
var iCheckCount = 0;
var iQuestionCount = document.getElementById('QuestionCount').value;

alert("Total number of checkbox questions = " + iQuestionCount);

for (var i=1; i <= iQuestionCount; i++) {
bFlag = false;
iCheckboxCount = document.getElementById('cbCount' + i).value;
iCheckCount = 0;

for (var j=1; j <= iCheckboxCount; j++) {
if (document.getElementById("chk" + i + "_" + j).checked) {
iCheckCount += 1;
bFlag = true;
}
}

alert("Number " + i + ", " + iCheckCount + " out of " +
iCheckboxCount + " are checked.");

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();
}

}


Jun 14 '06 #33

P: n/a
cl********@hotmail.com wrote:
O.k now we are talking. Not sure what the difference was but now it is
working.
Yes, strange how the JavaScript started working out of the blue!
Ben can I ask you one final question since you are a genious. Do you
know how to insert date time into an oracle database. What I mean is
how would I get the current date time when the user submits the form to
the database. Here is my sql insert that does work for all the other
parameters but not for date time. I also think there is something
wrong with my double and single quotes but I cannot see it. The
following works to add date but not time. How do I get datetime into
an oracle database. Thanks again for all your help.

CurDate = year(date) & left("00",2-len(month(date))) & month(date) &
left("00",2-len(day(date))) & day(date)

ssqlCheckBox = "INSERT INTO
Survey_User_Answer(Survey_Id,Question_Id,Answer_Id ,Date_Answer,User_ID)
VALUES (" & SurveyID & ",'" & objRS("Question_Id") & "' , '" &
answerChoices(answerChoice) & "' , TO_DATE("&CurDate&"), 'user')"


I'm definitely no genius when it comes to Oracle -- I've actually never
used it. However, Oracle should have some type of getdate() function
like SQL Server does. Unless you're using the CurDate variable for
something in your ASP code, you really don't need it at all which
should greatly simplify your INSERT sql statement. If this was an
INSERT statement for SQL Server, it would look like:

ssqlCheckBox = "INSERT INTO Survey_User_Answer (Survey_Id, Question_Id,
Answer_Id, Date_Answer, User_ID) VALUES (" & SurveyID & ",'" &
objRS("Question_Id") & "' , '" & answerChoices(answerChoice) & "' ,
getdate(), 'user')"

Note how CurDate is not needed and getdate() will insert the current
date AND time.

I would try to find out what the built-in Oracle function is for
getting the current date and time either from another newsgroup or it
should be in a manual somewhere.

Good luck,
Ben

Jun 15 '06 #34

P: n/a
Ben so sorry I just realized one other problem not with the datatime
but with the checkboxes. If the user fills in something for
other(which is a textbox) it should still let the user submit. So what
I am saying for some questions you may have checkbox answers or an
answer called other that is a textbox. If the user fills in the
textbox this is equivalent to checking a checkbox. Sorry.

As for the oracle date function it is sysdate. Thanks again.

Ben Amada wrote:
cl********@hotmail.com wrote:
O.k now we are talking. Not sure what the difference was but now it is
working.


Yes, strange how the JavaScript started working out of the blue!
Ben can I ask you one final question since you are a genious. Do you
know how to insert date time into an oracle database. What I mean is
how would I get the current date time when the user submits the form to
the database. Here is my sql insert that does work for all the other
parameters but not for date time. I also think there is something
wrong with my double and single quotes but I cannot see it. The
following works to add date but not time. How do I get datetime into
an oracle database. Thanks again for all your help.

CurDate = year(date) & left("00",2-len(month(date))) & month(date) &
left("00",2-len(day(date))) & day(date)

ssqlCheckBox = "INSERT INTO
Survey_User_Answer(Survey_Id,Question_Id,Answer_Id ,Date_Answer,User_ID)
VALUES (" & SurveyID & ",'" & objRS("Question_Id") & "' , '" &
answerChoices(answerChoice) & "' , TO_DATE("&CurDate&"), 'user')"


I'm definitely no genius when it comes to Oracle -- I've actually never
used it. However, Oracle should have some type of getdate() function
like SQL Server does. Unless you're using the CurDate variable for
something in your ASP code, you really don't need it at all which
should greatly simplify your INSERT sql statement. If this was an
INSERT statement for SQL Server, it would look like:

ssqlCheckBox = "INSERT INTO Survey_User_Answer (Survey_Id, Question_Id,
Answer_Id, Date_Answer, User_ID) VALUES (" & SurveyID & ",'" &
objRS("Question_Id") & "' , '" & answerChoices(answerChoice) & "' ,
getdate(), 'user')"

Note how CurDate is not needed and getdate() will insert the current
date AND time.

I would try to find out what the built-in Oracle function is for
getting the current date and time either from another newsgroup or it
should be in a manual somewhere.

Good luck,
Ben


Jun 15 '06 #35

This discussion thread is closed

Replies have been disabled for this discussion.