This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JSP and the fly likes Getting value of radio button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Getting value of radio button" Watch "Getting value of radio button" New topic
Author

Getting value of radio button

duhit Choudhary
Ranch Hand

Joined: Apr 01, 2012
Posts: 64
Hello All,
I made two radio buttons as:


but when i tried to fetch the value of radio button via following line of code:


I got NullPointerException on the same line. So can anyone tell me the right way to get the value of radio button.

Thanks in Advance
Devendra Bhati
Greenhorn

Joined: Dec 27, 2012
Posts: 19
Dear friend,

Why you hard coded value of radio control in java code. The best practice says, you need to get the value of input controls dynamically. So try to fetch the values of radio buttons from javaScript/jQuery and then request to server to GET/POST method.

I'm not sure but might getParameter() method will accept radio name instead of value. So please check out this.

All the Best. :)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63208
    
  69

You must use the name, not the value of the radio button.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
duhit Choudhary
Ranch Hand

Joined: Apr 01, 2012
Posts: 64
Bear Bibeault wrote:You must use the name, not the value of the radio button.


I have used name with following line of code


But now the problem is it is not giving the string value. i used toString() method for it but still not getting the string. what should i do???
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63208
    
  69

getParameterValues() returns a string array. If that's not what you want, why are you calling it?
duhit Choudhary
Ranch Hand

Joined: Apr 01, 2012
Posts: 64
Bear Bibeault wrote:getParameterValues() returns a string array. If that's not what you want, why are you calling it?




this will not helping me at all... the final thing i want to do is to:


But it is not going inside if(). What i am doing wrong here
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63208
    
  69

In Java, how does one compare strings?

Hint: it's not with ==
duhit Choudhary
Ranch Hand

Joined: Apr 01, 2012
Posts: 64
ok.. i got it.
with .equals()!!!
 
Have you checked out Aspose?
 
subject: Getting value of radio button
 
jQuery in Action, 3rd edition