get checkbox value

Reply

Join Date: Nov 2006
Posts: 2
Reputation: fariba123 is an unknown quantity at this point 
Solved Threads: 0
fariba123 fariba123 is offline Offline
Newbie Poster

get checkbox value

 
0
  #1
Nov 27th, 2006
i have a form with multiple checkbox. how to get the values that are checked.

pls give a quick reaply.

thanks
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: get checkbox value

 
0
  #2
Nov 27th, 2006
var checkBox = document.getElementById(boxID);
checkBoxValue = checkBox.value;
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 10
Reputation: the_count is an unknown quantity at this point 
Solved Threads: 1
the_count's Avatar
the_count the_count is offline Offline
Newbie Poster

Re: get checkbox value

 
0
  #3
Nov 27th, 2006
if you are posting it using a PHP form
then you will use something like that


($_POST['checkboxname] == "ON")

if you want to see what checkboxes are checked you have to declare them as an array then loop through them

see this link

http://www.daniweb.com/techtalkforums/thread62312.html
The day will soon come.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 7
Reputation: nickclarson is an unknown quantity at this point 
Solved Threads: 1
nickclarson nickclarson is offline Offline
Newbie Poster

Re: get checkbox value

 
0
  #4
Nov 27th, 2006
Or if you are talking about a group of checkboxes with the same name you would do something like this:

page_html.php
  1. <form method="post" action="">
  2. <input type="checkbox" id="things[]" value="red"> Cat<br>
  3. <input type="checkbox" id="things[]" value="blue"> Mouse<br>
  4. <input type="checkbox" id="things[]" value="green"> Car<br>
  5. <input type="checkbox" id="things[]" value="yellow"> DaniWeb
  6. </form>

page_php.php
  1. <?php
  2. $things = serialize($_POST['things']);
  3.  
  4. $query = "INSERT INTO table(things) values($things)";
  5. mysql_query($query) or die(mysql_error());
  6. ?>

basically just turn it into an array and dump the crap into a db. Notice that you have to "serialize" the data first and don't forget to "unserialize" when you are taking the data back out of the db (selecting).

You will then most likely have to implement a loop when you take the "crap" out of the db (as it will be in an array). The following link is a really good article on this, I would check it out.

Storing form array data to MySQL using PHP
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC