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
  • 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java script read and write file - save as location 8 42
Web forms being filled out by bots 4 31
Jquery 10 19
Call a function within the ASP code 4 4
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now