aspose file tools
The moose likes JSP and the fly likes Getting value of radio button Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply 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: 56151
    
  13

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 56151
    
  13

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: 56151
    
  13

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()!!!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Getting value of radio button
 
Similar Threads
java script problem
jsp file with java script error?
Multiple Forms and Radio Buttons
Display div's based upon selection of radio Buttons.
radio buttons selection