• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unchecked radio not passing null  RSS feed

 
Mo Alexwainy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i need to know how can i validate that a radio button has been checked.


the below null checking is not working.

servlet 1:
out.println("<input type=radio name=chbx id=xcv value="+getid+">");

servlet 2:
String book = request.getParameter("chbx");
if(book == null){
response.sendRedirect("/servlet");
}
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36656
475
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only have one radio button? Radio buttons are typically a group of things. It seems lie you'd want a checkbox here.

Also, try outputting this to see what the value is. That will give a clue why it isn't what is expected.


 
Mo Alexwainy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No this is a set of radio buttons automatically generated in a table whenever a record is added/parsed.
Even if i dont click a radio button and click the edit button to call a servlet to edit this record, i am not able to catch a null string.

So in the first servlet, let's suppose no radio button is selected and user clicked edit a blank page i need the user to stay on this page not going to a blank page.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65898
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With a radio button group, the value of the single parameter will be the value attribute of whichever radio button is checked. You will not get null values for unchecked buttons.

Your page should make sure that at least one default choice is checked when the page is presented to the user.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!