all groups > inetserver asp db > june 2006 >
You're in the

inetserver asp db

group:

need help- Submitting Check Box values to Table


need help- Submitting Check Box values to Table Gaby
6/15/2006 11:39:10 AM
inetserver asp db: im trying to make an online survey. the answers are different check
boxes.
I have this written out already. maybe you guys can help.
ill give you the abbreviated sample of it:

-------

<HTML>

<HEAD>

<TITLE>Sample</title>




<%


strFilePath = server.MapPath("database.mdb")

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFilePath
& ";"
Set rst = Server.CreateObject("ADODB.Recordset")
rst.LockType = 2

%>

<%
'opening database connection

'add record to my table

FUNCTION WriteToFile()
strSQL = "SELECT * FROM Table1"
rst.Open strSQL, strConn

rst.addnew

rst("ID#") = request.form ("ID#")
rst("Name") = request.form ("Name")



rst("Box1") = request.form ("Box2")
rst("Box2") = request.form ("Box2")



rst.Update
rst.Close
End Function
%>
</HEAD>
<BODY>

<FORM name= frmTEST1 method=post action= >


<Select name="menu" >
<option value="Instructor">Select Name</option>
<option value="Name1"> Name1</option>
<option value="Name2"> Name2</option>
</select>
&nbsp &nbsp

</Select>
&nbsp &nbsp

ID#.
<input type="text" size="12" maxlength="6" name="ID#" value="ID#"
id="ID##" />
<br>
<br>

01. <input type="checkbox" id="box1" name="box1" value="1" /> <label
for="box1">This is statement 1</label>
<BR>
02. <input type="checkbox" id="box2" name="box2" value="1" /> <label
for box2">This is statement2</label>
<BR>

<Center>

' --- SUBMIT BUTTON ---- />
<INPUT TYPE='submit' value="Submit" name="Submit_ICL"
onClick="WriteToFile();">

</FORM>

--------

This is a short sample of the code i have. When i try it the page
reloads and the answers reset but the info is ot going to the database.
i know im missing the action=___ whenever i declare my form but i dont
know what to put or if what im missing that will make mine work.
eventually i will work on validating it but for know can someone pleae
help
Re: need help- Submitting Check Box values to Table Gaby
6/15/2006 1:46:58 PM
I am now getting a syntax error (Microsoft VBScript compilation error
'800a03ea' )for the line that says

[quoted text, click to view]

any ideas?
thanks for the help so far. i understood the changes you made.
Re: need help- Submitting Check Box values to Table Gaby
6/15/2006 1:48:22 PM
i get a syntax error (Microsoft VBScript compilation error '800a03ea' )
on this line----> IF func = "submitForm" Then
[quoted text, click to view]

any ideas?
thanks for your help so far.

gabriel
Re: need help- Submitting Check Box values to Table James Jones
6/15/2006 1:52:01 PM
Ok. i think i know what you want.......

say your page is named TEST.ASP.........set your form to that........when i
do pages like this, that use forms, i create a varible that tells the page
what to do.....such as............


<%
func = Request.Form("func")

IF func = "" Then
%>
<FORM name= "frmTEST1" method="post" action="TEST.ASP">
<input type="hidden" name="func" value="submitForm">
<Select name="menu" >
<option value="Instructor">Select Name</option>
<option value="Name1"> Name1</option>
<option value="Name2"> Name2</option>
</select>
&nbsp &nbsp

</Select>
&nbsp &nbsp

ID#.
<input type="text" size="12" maxlength="6" name="ID#" value="ID#"
id="ID##" />
<br>
<br>

01. <input type="checkbox" id="box1" name="box1" value="1" /> <label
for="box1">This is statement 1</label>
<BR>
02. <input type="checkbox" id="box2" name="box2" value="1" /> <label
for box2">This is statement2</label>
<BR>

<Center>

' --- SUBMIT BUTTON ---- />
<INPUT TYPE='submit' value="Submit" name="Submit_ICL">
</FORM>
<%
End IF

IF func = "submitForm" Then

strFilePath = server.MapPath("database.mdb")

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFilePath
& ";"
Set rst = Server.CreateObject("ADODB.Recordset")
rst.LockType = 2

%>

<%
'opening database connection

'add record to my table

strSQL = "SELECT * FROM Table1"
rst.Open strSQL, strConn

rst.addnew

rst("ID#") = request.form ("ID#")
rst("Name") = request.form ("Name")



rst("Box1") = request.form ("Box2")
rst("Box2") = request.form ("Box2")


rst.Update
rst.Close
End IF
%>




give that a shot...........hope it works, if not, sorry






















[quoted text, click to view]

Re: need help- Submitting Check Box values to Table James Jones
6/15/2006 3:57:56 PM
ok........then we will do an ELSE intead of another IF....................



<%
ELSE



strFilePath = server.MapPath("database.mdb")

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFilePath
& ";"
Set rst = Server.CreateObject("ADODB.Recordset")
rst.LockType = 2

'opening database connection

'add record to my table

strSQL = "SELECT * FROM Table1"
rst.Open strSQL, strConn

rst.addnew

rst("ID#") = request.form ("ID#")
rst("Name") = request.form ("Name")



rst("Box1") = request.form ("Box2")
rst("Box2") = request.form ("Box2")


rst.Update
rst.Close
End IF
%>





[quoted text, click to view]

Re: need help- Submitting Check Box values to Table Gaby
6/20/2006 11:04:09 AM
I tried many different variations and I cant get this to work. If any
of you experts are up for it, I wouldnt mind emailing you my code.
Many having someone else proof read it I may find something wrong. I
did i noticed when I submit the form and if i hit REFRESH i get "The
page cannot be refreshed without sending the information". So theres
got to be something with the connection i would think. Email me if you
wouldnt mind helping me out and i will send what I got to you.

Thanks.
Gabriel
Re: need help- Submitting Check Box values to Table Mike Brind
6/20/2006 2:58:51 PM

[quoted text, click to view]

To start with, don't create a recordset to add a new record. Second,
you have a javascript call to a function - onClick="WriteToFile() -
calling server side asp code. That won't work. Third, you are trying
to reference an input called Name that doesn't exist on your form.

Here's your form:

<form name="frmTEST1" method="post">
<select name="Instructor" >
<option value="">Select Name</option>
<option value="Name1"> Name1</option>
<option value="Name2"> Name2</option>
</select>

<p>
ID#.
<input type="text" size="12" maxlength="6" name="ID#" id="ID##" />
</p>
<p>
01. <input type="checkbox" id="box1" name="box1" value="1" /> <label
for="box1">This is statement 1</label>
</p>
<p>
02. <input type="checkbox" id="box2" name="box2" value="1" /> <label
for box2">This is statement2</label>
</p>
<p>
<input type="submit" value="Submit" name="Action" />
</p>
</form>

In the same page, do this:

<%
On Error Resume Next
If Request.Form("Action") = "Submit" Then
strFilePath = server.MapPath("database.mdb")
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFilePath
conn.open strConn
p1 = Request.Form("Instructor")
p2 = clng(Request.Form("ID#"))
p3 = cint(Request.Form("Box1"))
p4 = cint(Request.Form("Box2"))
If Err.Number<>0 Then
Response.Write "Your record has not been added"
Else
conn.qInsertRecord p1, p2, p3, p4
Response.Write "Your record has been added"
End If
End If
%>

Now, in your database, go to the Query pane and select New Query in
Design View. Close the Show Tables dialogue box that opens, then click
the SQL button in the top left. In the new window that opens, copy
this in, making the necessary changes for your table and field names:

INSERT INTO Table1 (ID#, Instructor, Box1, Box2) VALUES ([p1], [p2],
[p3], [p4])

Save that as qInsertRecord. Then run the query and enter values as
prompted to make sure it works. If it does, that's it. You're done.

--
Mike Brind
Re: need help- Submitting Check Box values to Table Gaby
6/22/2006 10:46:29 AM
Mike I took what you wrote and made some changes to alter it some....
Bottom Line: IT WORKED GREAT.

Thanks again for your help.

Gabriel
AddThis Social Bookmark Button