Adding checkboxes

Javascript coding ..

Moderators: macek, egami, gesf

gregd
New php-forum User
New php-forum User
Posts: 1
Joined: Fri Apr 27, 2012 5:55 pm

Adding checkboxes

Postby gregd » Tue May 15, 2012 10:07 am

OK, I am a newbe

Say I have a bunch of checkboxes

Code: Select all

 <tr>
   <td colspan='2' class='normal'><input type='checkbox' name='formCheck1'>Check If this Form is Correct</td>
 </tr>
 <tr>
   <td colspan='2' class='normal'><input type='checkbox' name='formCheck2'>Check If this Form is Correct</td>
 </tr>
  <tr>
   <td colspan='2' class='normal'><input type='checkbox' name='formCheck3'>Check If this Form is Correct</td>
 </tr>
  <tr>
   <td colspan='2' class='normal'><input type='checkbox' name='formCheck4'>Check If this Form is Correct</td>
 </tr>




And in a function I want to add the number of checkboxes checked.

I am looking for some kind of hack.
I would rather not have to do this over and over

Code: Select all

if(!formname.formCheck1.checked)
{
}



I have tried

Code: Select all

x = x + ormname.formCheck1.checked

Hoping that a true might work as a 1.

Does anyone know an easy way for this to be done?

thanks

User avatar
WebOutGateway
New php-forum User
New php-forum User
Posts: 37
Joined: Mon Jun 13, 2011 9:25 pm
Location: Pasig City, Philippines
Contact:

Re: Adding checkboxes

Postby WebOutGateway » Mon Aug 04, 2014 10:01 pm

Hi!

You can use the :checked selector. It matches all elements that are checked. It works with checkboxes and radio buttons.

Here is my reference:
http://api.jquery.com/checked-selector/

I hope this helps. Thank you.


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 2 guests