function read()

var numbers = new Array();

for (i = 0; i < field.length; i++)
    numbers[i] = document.test.checkboxName.value;

var counter=0;

//Let's print out the elements of the array.
for (counter=0; counter<numbers.length; counter++)
   document.write(numbers[counter] + "<br>");

I want to read the values of the checkboxs and store the vlaues into an array (there are more than 1 checkboxs) the form name is text and the names of the check box = checkboxname

any help would be appreciated as i dont know where i am going wrong

7 Years
Discussion Span
Last Post by osirion666

okay decided to do it in JSP


<form ACTION="index.jsp">
<input type="checkbox" name="id" value="0000"> bob<BR>
<input type="checkbox" name="id" value="1111"> john<BR>
<input type="checkbox" name="id" value="2222"> paulk<BR>
<input type="checkbox" name="id" value="3333"> roger<BR>
<input type="checkbox" name="id" value="4444"> marc <BR>
<input type="submit" value="Submit">

String numbers[] = request.getParameterValues("id");
if (numbers != null && numbers.length != 0) {
out.println("You have selected: ");
for (int i = 0; i < numbers.length; i++) {

For any one who is having similar trouble
got the tut from roseindia


you can manipulate form element's by simply icrementing it using the element propreties:

var chbVal = [];
for ( var x = 0; x < form.elements.length; x++ ) {

// checkbox ids can also be provided in replace of x varible.
// But if you have no other elements in the form asside from checkboxe, the x variable will do the job. 
   chbVal[x] = form.elements[x].value;
} // All the checkbox value is now stored in the chbVal array.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.