Solved

Triggering Select-All in JSP

Posted on 2011-02-18
4
415 Views
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>
</s:iterator>

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];
           if(element.name.indexOf('checkbox')!=-1)
           {
                 checkboxelements[cnt] = element;
                 alert(checkboxelements[cnt].checked);
                 cnt++;
           }
        }
        
        if(checkboxelements!=null)
        {
             
                           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.

Thanks
0
Comment
Question by:abuyusuf
  • 2
4 Comments
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 34925611
see this example
<script>
	function selectall(obj)
	{
			if(obj.checked)
			{
				var input = document.getElementsByTagName("input");
				for(i=0;i<input.length;i++)
				{

					if(input[i].type == 'checkbox')
					{
						input[i].checked=true;

					}

				}

			}
	}
  </script>
 </HEAD>

 <BODY>
  <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
 </BODY>

Open in new window

0
 

Author Comment

by:abuyusuf
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
Thanks
0
 
LVL 20

Expert Comment

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

Accepted Solution

by:
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

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What does GoogleTagMgr javascripts below do 5 34
how can i get 4 nd 5 ? 3 31
Bot application - advice 3 38
Possible propagation problem 1 22
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

856 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