wood burning stoves 2.0*
The moose likes JSP and the fly likes How to get a scriptlet value for javascript validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to get a scriptlet value for javascript validation" Watch "How to get a scriptlet value for javascript validation" New topic
Author

How to get a scriptlet value for javascript validation

hrin kuek
Greenhorn

Joined: Mar 24, 2005
Posts: 9
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
hrin kuek
Greenhorn

Joined: Mar 24, 2005
Posts: 9
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

Joined: Mar 24, 2005
Posts: 9
The whole code is like that:

Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get a scriptlet value for javascript validation
 
Similar Threads
select the chekbox generated at runtime of jsf page using javascript
Changing the default behaviour for check box ?
form inputs in servlets
reading a nested list with javascript
Need Help with binding click events to table rows