 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 19th, 2007, 02:46 PM
|
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Nope, if I submit it with its value set as off then it work but only if its ticked, and if its set to on then it submits as normal.
|
|

February 19th, 2007, 02:58 PM
|
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If the form code is as below
Code:
<input type ="checkbox" name ="carYESNO" value = "off"/>
and the chkbox is checked then it passes the value 'off' to the string because I am overiding its defult.
This is with the above form setting and the check box ticked
Code:
INSERT INTO tblHome (memberID, towncity, towndistance, towndirection, propertytype, flatfloor, flatblock, nobedrooms, nobathrooms, maxnoofpeople, carneeded, carexchange, smoking, swimpool, petcare, childrenallowed, plantcare, additionalinfo, picture)values ('2', 'London', '15', 'SE', 'Flat', '3', 'CC', '2', '2', '4', off, on, on, on, on, on, on, 'hello', '');
If it is unticked then its passed as undefined
|
|

February 19th, 2007, 03:05 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Consider this:
<%@Language=VBScript%>
<%
If Request.Form("cb") <> "" then
Response.Write("cb value is: " & Request.Form("cb"))
Else
%>
<form action="./test.asp" method="POST">
<input type ="checkbox" name ="cb" value = "on"/>
<input type="submit" text="submit" value="submit" />
</form>
<% end if %>
when navigating to this page, the form will be displayed if you neglect to check the checkbox and press submit, the form will be displayed again. If and only if, the checkbox is checked will it execute the response.write line. When the response.write executes it will read: cb value is: on
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
|
|

February 19th, 2007, 03:47 PM
|
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok I get the logic in what you have shown me, my checkboxes are optional. The code you have given will not allow the form to post if the chkbox is not checked.
If I may post a link to the page I am working on:
http://cms-stu-iis.gre.ac.uk/mg511/SHIC/register.html
There is a response.write in there to show the sql query, please feel free to try it.
Sorry about the amount of time I am taking here, once I have this the rest should be simple (I hope)
|
|

February 19th, 2007, 04:13 PM
|
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok, with my tail between my legs I have come to realise that the simplest thing actually worked.
Thank you so much, I have been on this for days and you have given me the simplest solution and it works.
I guess the only other question is whether you have an idea of how to make it catch all the checkboxes. Other wise itâs a lot of if statements.
Thank you again, you donât know how grateful I am.
|
|

February 19th, 2007, 04:23 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Unfortunately, no. This is one of the bad things about ASP is that it is extremely redundant when it comes to things like this so the ifs are all almost necessary.
What you could do would be to create 2 arrays one that stored the name of the field, the other that stored a value associated with the field; something like
for i = 0 to UBound(someArray)
if request.form(someArray(i)) != 'on' then
anotherArray(i) = 'off'
end if
next
hth
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
|
|

February 19th, 2007, 04:54 PM
|
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Again thanks for the help, with this. I will be working on the array method I think, but to be honest everything in this post only makes sense now its working.
Cheers
Graham
|
|
 |