Meaningless Drivel is fun!
The moose likes JSP and the fly likes Problem in getting the state of checkbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem in getting the state of checkbox" Watch "Problem in getting the state of checkbox" New topic

Problem in getting the state of checkbox

Polireddy Vanukuri

Joined: Jul 24, 2006
Posts: 6
I have a JSP file which connects to DB and dispaly in aTable format by putting a checkbox as a first column of every row dispay. I am giving a name to every checkbox but its not a static name , its a name given dynamically by incrementing a varible in the process of looping(while)The checkbox names are

As the browser won't send the checkbox stauts which is not checked(for that it is throw NullPointerException,i verified), I m using hidden filelds. i m giving the name to them as chbSetState0,chbSetState1,chbSetState2,.... i m giving Initial values for these are as 0(zeroes).

I m going to set corresponding hidden value to 1,when the user clicks a checkbox. For that i m calling the function .. setState().
To set a hidden value to 1, i have to get the index name of the checkbox
that the user checked,that means i have to append that index value(index_chbSelected) to the hidden field name in this way....
// getting the index of check box clicked

// setting the corresponding hidden value

But its an error javascript.

The logic i written is to know the other page(jsp page will get the hidden field values.If a hidden field value is 1,it treats check box selected)get checkbox state in the current jsp page.

I tried so much to get solution for this.

If any one understood my problem, pls help me to solve this problem.
[ July 29, 2006: Message edited by: Bear Bibeault ]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Javascript issues are discussed in our HTML/Javascript forum but before sending this thread there, let me suggest another approach.

If you're creating the names with an incrementing number, you should be able to read them the same way. Just be sure to create a hidden form field that contains the number of checkboxes (cbCount).

(Remember: getParameter returns null if you request a param that wasn't sent)

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Problem in getting the state of checkbox
It's not a secret anymore!