• 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

How to get a scriptlet value for javascript validation

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I need to ensure that at least one checkbox in my whole list of dynamic checkboxes are ticked. I think the problem is I don't know how to get the input name value out so that I can use javascript.

Hope someone can enlighten me. Hope to hear from you guys soon!

Appreciate the help..

Danielle Hrin
 
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
I'm having a hard time understanding what your question is. Please elucidate.

Also, it not necessary, and is very confusing, to mangle your code for posting. it is very straight-forward to just enter:



Otherwise, we have no way of knowing what your code really looks like.
 
hrin kuek
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops sorry for the confusion... The code is the way you have written it.

The thing is I have this javascript function that goes like this:


so that it will be able to look thru the whole list of my dynamic checkboxes to make sure I have ticked at least one checkbox. But it doesn't seem to work. Is it cos scriptlet is server-side scripting while javascipt is client-side? Is there anyway I can get around it?
 
hrin kuek
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The whole code is like that:

 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A mix of JSP/javascript. Possibly more javascript than JSP, but there are some dynamic elements to it.

I'm not sure exactly what the name of the checkbox is.
In your first post it is name="<%= modCode %>"
in the full code it is name="modCode"
Which is it?

From what I can see you have a list of modules.
Each module contains a list of tasks.
You generate a checkbox for each task in a module.

My assumption:
The validator has to make sure that for each moduleone checkbox is checked.

The javascript:
Here is a javascript function that will check to see if any checkboxes are checked for all the checkboxes in one group.
It also accounts for the cases where there are
- no checkboxes
- one checkbox
- multiple checkboxes.



Now the java/jsp bit.
You just need to call this function from your current validSecurityClass() function.

in the case that you only need one checkbox checked out of all of the checkboxes on the page, and it is name="modCode"
then this will do the trick:

var checkBoxChecked = validateCheckBoxes(thisForm, "modCode");

If it is name="<%= modCode %>"

you need to generate multiple calls to make sure that for each module, at least one task is clicked:

var checkBoxChecked = "true";
// loop for Each module:
checkBoxChecked = checkBoxChecked && validateCheckBoxes(thisForm, "<%= modCode %>");

which will generate code like this:


The final thing I would suggest is to use JSTL for looping rather than scriptlet code. It would be much neater than scriptlet code ;-)

Good luck,
evnafets
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic