Triggering Select-All in JSP

Posted on 2011-02-18
Last Modified: 2013-11-23
Hi - I have a JSP page with multiple check boxes - the check boxes are populated on the screen using a Struts 2 Tag as follows

<s:iterator value="myList" status="status">
<td align="center"><s:checkbox name="myList[%{#status.index}].checkboxName"/></td>

I have another checkbox on the screen which when clicked should trigger selection of all other checkboxes on the screen. The following is the Javascript

function toggle(source,status)
   var checkboxelements = new Array();
   var cnt = 0;
        for (var counter=0; counter < source.document.forms[0].elements.length; counter++)
           var element = source.document.forms[0].elements[counter];
                 checkboxelements[cnt] = element;
                           for (var counter=0; counter < checkboxelements.length; counter++)
                                  checkboxelements[counter].checked = 'true';

Triggering the above does not seem to help enable all the checkboxes - not sure what I'm missing but the status of the existing checkboxes comes back correctly.

Question by:abuyusuf
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 20

Expert Comment

by:chaitu chaitu
ID: 34925611
see this example
	function selectall(obj)
				var input = document.getElementsByTagName("input");

					if(input[i].type == 'checkbox')




  <input type='checkbox' id='selectall' onclick='selectall(this)'>Select all
  <input type='checkbox' id='checkbox1'>11111
  <input type='checkbox' id='checkbox2'>222222
  <input type='checkbox' id='checkbox3'>333

Open in new window


Author Comment

ID: 34926337
Hi chaituu
Thanks for responding I tried that but it doesn't work for some reason. I am using struts tags. Appreciate the help
LVL 20

Expert Comment

by:chaitu chaitu
ID: 34926433
take view source code after displaying the page and paste it here
LVL 20

Accepted Solution

Sathish David  Kumar N earned 250 total points
ID: 34928715

not like this
checkboxelements[counter].checked = 'true';

change like this
checkboxelements[counter].checked = true;

bcz if u give in singel qutoe means it will take it as string


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Timer on div 5 23
disable and enable textboxes in dataTable 7 24
Making Table Thru ASP Response.write 5 19
activeMQ Queue Messages Enqueued and Messages Dequeued 1 27
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question