Forums

ASP

This topic is locked

checkbox form field error

Posted 07 Mar 2007 07:20:39
1
has voted
07 Mar 2007 07:20:39 susan haft posted:
I have handcoded an insert statement for a form which contains a checkbox. If the form is submitted with the box checked, all is fine. If the checkbox is left unchecked, I receive an insert statement syntax error message.The problem doesn't seem to lie in the database as I have set the default value to "False" and null values are acceptable. My guess is that the syntax error message is caused by an imbalance in the insert statement. Let me expain.

In my insert statement, I am stating that the value of the checkbox field "&Request.Form("emailprob_mor"&" should insert into emailprob_mor. The problem is that when the checkbox is left unchecked, it is as though the form field does not exist at all.

This is evident because for testing purposes, I have set the form's method to "GET" and have left the checkbox unchecked. All of the page's form fields pass on as a url parameter even though they are null

usacity_cus=&shstateid_stt=51&shpostalcode_cus=&addcustomer=submit

but there is no allusion at all that the checkbox field exists and the insert statement depends on it (I guess)

Replies

Replied 07 Mar 2007 12:06:58
07 Mar 2007 12:06:58 Lee Diggins replied:
Hi Susan

You're quite right, if a checkbox is not selected then it isn't passed for processing. The best way to solve this is to chack to see if the there's a value for the checkbox and alter your insert statement accordingly, something like this:

<pre id=code><font face=courier size=2 id=code>
&lt;%
Dim checkbox_test
If Request.Querystring("checkbox" = "" Then
checkbox_test = "Checkbox Not Processed"
Else
checkbox_test = "Checkbox Processed"
End If

Response.Write(checkbox_test)
%&gt;
&lt;form name="form1" method="get" action=""&gt;
&lt;input type="checkbox" name="checkbox" value="valueOfMyCheckbox"&gt;
&lt;input type="submit" name="Submit" value="Submit"&gt;
&lt;/form&gt;
</font id=code></pre id=code>

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 07 Mar 2007 23:29:28
07 Mar 2007 23:29:28 susan haft replied:
thanks a lot. That did the trick!

Reply to this topic