| 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
|
|
|
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
|
|
|
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
|
|
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()!!!
|
 |
 |
|
|
subject: Getting value of radio button
|
|
|