aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Passing check box value to servlet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Passing check box value to servlet." Watch "Passing check box value to servlet." New topic
Author

Passing check box value to servlet.

hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Hello guys,

Got little bit tangled here...

I have a table in my jsp page..



On click of any check box in the table, it should be transferred to a servlet from there it should call a method where I have my business logic.

I am trying to do it through the following way,

I am calling a javascript function on "onselect" in checkbox ,and from there i am trying to call "document.location.href = my servlet name "

It seems not to work, could anyone help me out..

Thanks and regards,
Hemanth.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61747
    
  67

"onselect"? Have you verified that that's a valid event for checkboxes?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Hi Bear Bibeault,

Thanks for early response...

Yeah, "onselect" seem not to work for checkboxes, i made a work around for that functionality which i wanted..... I will get back to you once its fully functional...

Thank you,
Hemanth
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61747
    
  67

What you have you done to find out what events are valid for checkboxes?
hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Bear Bibeault,

It was a trial and error method, just placed onselect and assigned a javascript for it... Seem not to work..


Thank you,
Hemanth.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61747
    
  67

Do you think that the trial and error method is effective? Maybe it'd be helpful to get yourself a good JavaScript and DOM reference so that you'd know for sure what to use?
hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Bear Bibeault,

Yeah , I will do that, But for now my work around seem to do the trick...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61747
    
  67

hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
why was that for ....

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9317
    
  17

hemanth, what Bear is trying to say is onselect is not an event of checkbox. If its not working then the trial and error method says its wrong. Check the input tag page to see the events which input tag supports...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Ankit,

Oops , My bad.. I will do that...

Thank you,
Hemanth.
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

Worse yet, trial and error may produce results that work in 'some' browsers but not in others, since not all browsers properly implement specs. In other words, the documentation is not just better to use because it will get to the correct solution faster, but will also be more reliable across multiple browsers and platforms.


My Blog: Down Home Country Coding with Scott Selikoff
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1757
    
    3
Programming by Coincidence
Tina Ma
Ranch Hand

Joined: Nov 29, 2007
Posts: 198
If each of your checkbox item has an 'id' and a 'name' , you can use
HttpServletRequest.getParamterValues('name') to retrieve a String array containing the list of 'checked' ids.


Tina
SCJP 1.4, SCWCD 1.4
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61747
    
  67

Tina Ma wrote:If each of your checkbox item has an 'id' and a 'name' , you can use
HttpServletRequest.getParamterValues('name') to retrieve a String array containing the list of 'checked' ids.

No, you can't. The ids are not, I repeat not, submitted as part of the request. Only the names and values are.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing check box value to servlet.