Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 117,283 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 2,180 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Getting the number of checkboxes in a php form

 
Reply to this topicStart new topic

Getting the number of checkboxes in a php form

ashaajith
post 14 Jul, 2008 - 02:06 AM
Post #1


New D.I.C Head

*
Joined: 10 Jul, 2008
Posts: 22

I am developing a facebook app in php. I have a form with some checkboxes. Is there a way to get the count of checkboxes .
User is offlineProfile CardPM

Go to the top of the page


MitkOK
post 14 Jul, 2008 - 02:38 AM
Post #2


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 289



Thanked 9 times

Dream Kudos: 250
My Contributions


If you have multiple checkboxes :

HTML

<form name="myform" action="" method="POST">
<input type="checkbox" name="options[]" value="Mac OS X">Mac OS X
<input type="checkbox" name="options[]" value="Linux">Linux
<input type="checkbox" name="options[]" value="Windows"> Windows
<input type="submit" value="Send me your name!">
</form>

You can get the count using this :

php
$boxcount = isset($_POST['options']) ? count($_POST['options']) : 0;

echo $boxcount;
User is offlineProfile CardPM

Go to the top of the page

ashaajith
post 14 Jul, 2008 - 03:04 AM
Post #3


New D.I.C Head

*
Joined: 10 Jul, 2008
Posts: 22

QUOTE(MitkOK @ 14 Jul, 2008 - 02:38 AM) *

If you have multiple checkboxes :

HTML

<form name="myform" action="" method="POST">
<input type="checkbox" name="options[]" value="Mac OS X">Mac OS X
<input type="checkbox" name="options[]" value="Linux">Linux
<input type="checkbox" name="options[]" value="Windows"> Windows
<input type="submit" value="Send me your name!">
</form>

You can get the count using this :

php
$boxcount = isset($_POST['options']) ? count($_POST['options']) : 0;

echo $boxcount;



Thanx for the post.
But what i need is to get the count of the checkboxes inside javascript for facebook


This post has been edited by ashaajith: 14 Jul, 2008 - 03:05 AM
User is offlineProfile CardPM

Go to the top of the page

MitkOK
post 14 Jul, 2008 - 03:18 AM
Post #4


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 289



Thanked 9 times

Dream Kudos: 250
My Contributions


I cannot uderstand you, you want to get the count using JavaScript or ... ?
User is offlineProfile CardPM

Go to the top of the page

ashaajith
post 14 Jul, 2008 - 03:27 AM
Post #5


New D.I.C Head

*
Joined: 10 Jul, 2008
Posts: 22

QUOTE(MitkOK @ 14 Jul, 2008 - 03:18 AM) *

I cannot uderstand you, you want to get the count using JavaScript or ... ?


i want to get the count of the checkboxes using javascript.

ie,

form.php

CODE

  <script language="javascript">
  function getcount()
{
  document.getElementById("test").length;
}


  </script>


<input type="checkbox" id="test" value="test">
<input type="checkbox" id="test" value="test">


The above javascript cod works fine if we are using just php. but here i am having a facebook app. so above method "length" is not supported.


** Edit ** code.gif

This post has been edited by no2pencil: 7 Aug, 2008 - 10:11 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/6/08 10:48PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month