Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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
 
Old February 19th, 2007, 02:46 PM
Authorized User
 
Join Date: Feb 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old February 19th, 2007, 02:53 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

A checkbox will only pass a value if its checked.

================================================== =========
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
 
Old February 19th, 2007, 02:58 PM
Authorized User
 
Join Date: Feb 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old February 19th, 2007, 03:05 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
 
Old February 19th, 2007, 03:47 PM
Authorized User
 
Join Date: Feb 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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)

 
Old February 19th, 2007, 03:55 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok try this logic.

if(var[cbname] != 'on')
{
var[cbname] = 'off';
}

================================================== =========
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
 
Old February 19th, 2007, 04:13 PM
Authorized User
 
Join Date: Feb 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.




 
Old February 19th, 2007, 04:23 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
 
Old February 19th, 2007, 04:54 PM
Authorized User
 
Join Date: Feb 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old February 19th, 2007, 04:58 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Good luck, glad you got it working.

================================================== =========
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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Registering checked checkboxes in a database KeviJay VB Databases Basics 4 May 14th, 2008 04:44 PM
MS ACCESS 2003 FRONTEND AND MS SQL SERVER 2005 DB mohankumar0709 SQL Server 2005 3 March 23rd, 2007 12:48 AM
Checkboxes undefined when not checked MS Access Morn Classic ASP Basics 0 February 15th, 2007 05:07 PM
Keep track of checkboxes checked in one CASE stmt markw707 Javascript How-To 0 December 29th, 2006 12:28 PM
how to set checked listbox in access application. Skyblue Access VBA 2 September 5th, 2003 09:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.