• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Select All boxes in html:multibox

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good evening,
I just wonder if you can give me, some help, with a validation of multiboxes, that i am developing.

I had search information of how to implement the action, that, when the user select the option "All", from a list of checkboxes, all the rest of objects are checked. This, using javascript

I had review this two posts and tried to adjust the solution to my problem, but with no possitive result.

https://coderanch.com/t/121183/HTML-CSS-JavaScript/multi-select-boxes#599576

https://coderanch.com/t/118337/HTML-CSS-JavaScript/add-checkbox-values-javascript-array#588193


The fragment of my code in JSP:




The function that I use in JavaScript:



But with no results, even when enter to the else, and it is supposed that change the checked status of the boxes to true, it doesn't reflect the result in the page.

If you can give some help, it would be great.

I really appreciate so much your time and knowledge!

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
html:multibox generates a set of checkboxes. Each has the same id which is a problem. Ids are supposed to be unique on a web page. Maybe you want to search by name instead? Also document.getElementById('selectedAct').length seems like a problem. If null is returned, the length is undefined. (And it doesn't make sense to get the length of one item anyway).

This example shows you can set one of the checkboxes using your else statement and a unique id. Try to gradually expand on it and save the resulting jsFiddle. Then post back with where you got stuck.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, posting the server-side markup isn't very helpful. It'd be best to post the actual HTML.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Each has the same id which is a problem. Ids are supposed to be unique on a web page


That's egregious, in my opinion. Frameworks that generate invalid HTML should be avoided at all costs. (Or at least avoid the tags that generate bad HTML.)
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not the framework's fault here.



styleId maps to the HTML id attribute. (because id means something else in Struts.) The code above corresponds to one checkbox. It is the fact that it is in a loop and has the same id each time that gives it the duplicate.

Hmm. I wonder if I'm scared from Struts 1 that I still remember that!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, that makes more sense. It'd be nonsensical for a framework to deliberately create bad HTML.

(It's been years and years and years since I've used Struts1, but I seem to remember it did some weird things with name and id but I may be remembering incorrectly.)
 
Adriana Corrales
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I did It! By using jQuery.v

I post the solution, in case anyone need it in a future


function selectAllChk(){
var procids = "";
var checked = true;
jQuery(":input:checkbox[name='selectedActions']:checked").each(function(){
procids += jQuery(this).val();
});
if (procids =="Select All"){
jQuery(":input:checkbox[name='selectedActions']").prop('checked', true);

}
}


I hava a variable named procids, because I need to check if the user select the option "Select All" from the List.
First, i get the checked option and after i evaluate it, to decide if I check or not all the options.


Thank you to all!
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for posting your solution.
reply
    Bookmark Topic Watch Topic
  • New Topic