Reputation: 43
Hi I'm new to classic asp and i just can't get my head around this simple problem. I have a form with 2 checkbox's in and this is the result i want:
If the user checks both checkbox's then insert a certain value into the database. Else insert a different value into the database. I've tried a few things but at the moment i'm trying to check if the checkbox doesn't have a value then insert but the else always fires. By default the user has to accept the terms checkbox.
Hope this makes sense. Thanks
<FORM method="POST" action="<% =Request.ServerVariables("SCRIPT_NAME")%>" >
<p> <input type="checkbox" name="Privacy" value="1" id="Privacy" >privacy checkbox<a href="javascript:void(0)" onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'"><img src="/images/qmark.png" /></a></p>
<p> <input onchange="this.setCustomValidity(validity.valueMissing ? 'Please indicate that you accept the Terms and Conditions' : '');" id="field_terms" type="checkbox" name="Terms" value="2" >I accept Terms and Conditions</p>
</form>
Then my asp looks like:
if Request.form("Privacy") <> "" Then
SQL = "INSERT INTO table1 (t1_accept) VALUES('N')"
cnSub.execute SQL
Else
SQL = "INSERT INTO table1 (t1_accept) VALUES('Y')"
cnSub.execute SQL
End If
Upvotes: 1
Views: 2034
Reputation: 11
Upvotes: 1
Reputation: 2239
Try this:
If Request.Form("Privacy") = "1" Then
SQL = "INSERT INTO table1 (t1_accept) VALUES('Y')"
Else
SQL = "INSERT INTO table1 (t1_accept) VALUES('N')"
End If
cnSub.execute SQL
Note this code does an explicit check if Privacy has a value of 1, if it is insert a value of Y into the table, otherwise any other value for Privacy will insert a value of N into the table.
Upvotes: 0