How to get the selected Checkbox Index or value in PHP/Javas

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 64
Joined: Thu Mar 14, 2013 6:10 am

Fri Aug 23, 2013 3:16 am

How to get the selected Checkbox Index or value in PHP/Javascript

Below is my UI table

the page where checkbox are created that is submitted to a Form
image001.png (7.13 KiB) Viewed 1052 times

php-forum Super User
php-forum Super User
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

Fri Aug 23, 2013 5:29 am

something like this (i have not tested this example):
assuming the checkboxes have the name called "myinput" and class name as "sampleCheckbox"

Code: Select all

var checkedValue = ''; 
var inputElements = document.getElementsByTagName('myinput');
for(var i=0; inputElements[i]; i++){
      if(inputElements[i].className==="sampleCheckbox" && inputElements[i].checked)
           checkedValue = inputElements[i].value;
something like this...

Post Reply