Matar Posted May 13, 2006 Share Posted May 13, 2006 hi i am trying to get the checkbox value to my db but its does'work how can give me a simple code ?? Link to comment Share on other sites More sharing options...
Yahweh Posted May 13, 2006 Share Posted May 13, 2006 hi i am trying to get the checkbox value to my db but its does'work how can give me a simple code ?? <{POST_SNAPBACK}> When you submit a form with a checkbox, it sends an empty string for unchecked boxes and sends the value of checked boxes just like any other form element. Example:animals.asp<form action="process.asp" method="post"><p>What kind of pets do you have:<br>Kitties: <input type="checkbox" name="animal1" value="true"><br>Bunnies: <input type="checkbox" name="animal2" value="true"><br>Puppies: <input type="checkbox" name="animal3" value="true"><br>Fishies: <input type="checkbox" name="animal4" value="true"></p><p><input type="submit" value="Submit"></p></form> Imagine that the user submitted the following data: Kitties [x]Bunnies [ ]Puppies [ ]Fishies [x] The page will send the following querystring: process.asp?animal1=true&animal2=&animal3=&animal4=true So, to put that information into a database, you use something like this: Dim Animal1, Animal2, Animal3, Animal4'The following automatically assign the variables declared above to a boolean'value of True or False based on whether they equal the word "true"Animal1 = Cbool(lcase(Request("animal1")) = lcase("true")) 'Returns TrueAnimal2 = Cbool(lcase(Request("animal2")) = lcase("true")) 'Returns FalseAnimal3 = Cbool(lcase(Request("animal3")) = lcase("true")) 'Returns FalseAnimal4 = Cbool(lcase(Request("animal4")) = lcase("true")) 'Returns True After you determine the value of your checkboxes, you can insert them into your database as usual: Dim Conn, RS, SQLSet Conn = Server.CreateObject("ADODB.Connection")Set RS = Server.CreateObject("ADODB.Recordset")sql = "SELECT * FROM table_to_update WHERE ID = 65"Conn.Open your_connection_stringRS.Open sql, Conn, 3, 3 RS("Animal1") = Animal1 RS("Animal2") = Animal2 RS("Animal3") = Animal3 RS("Animal4") = Animal4 RS.UpdateRS.CloseConn.CloseSet rs=nothingSet conn=nothing Link to comment Share on other sites More sharing options...
Dhanajee Posted May 14, 2006 Share Posted May 14, 2006 What is the data type of your database??? Link to comment Share on other sites More sharing options...
Matar Posted May 14, 2006 Author Share Posted May 14, 2006 hi thx Yahweh for your replay the data field type is yes / No Link to comment Share on other sites More sharing options...
justsomeguy Posted May 15, 2006 Share Posted May 15, 2006 Imagine that the user submitted the following data:CODEKitties [x]Bunnies [ ]Puppies [ ]Fishies [x]The page will send the following querystring:CODEprocess.asp?animal1=true&animal2=&animal3=&animal4=trueActually, oddly enough, it doesn't even send the unchecked boxes. The server receives this:process.asp?animal1=true&animal4=true Link to comment Share on other sites More sharing options...
aspnetguy Posted May 15, 2006 Share Posted May 15, 2006 What is the data type of your database??? <{POST_SNAPBACK}> Doesn't matter. A simple query like the one being used is the same on all database platforms. Link to comment Share on other sites More sharing options...
florynth Posted July 4, 2006 Share Posted July 4, 2006 I was working on a solution who's a lot better then this I know it's working on php probably on ASP toif you put a hidden input before the checkbox with the same name and the value to false and after the checkbox with the value to true normal since you have to field with the same name the last one will be keep.So because the info of a uncheck box is not send you will get false of the hidden field. <input name="accept" type="hidden" value="0" /><input name="accept" type="checkbox" value="1" /> You can event don't set the value of the hidden input it will send {field_name}= to the server... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now