• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Unchecked radio not passing null  RSS feed

 
Greenhorn
Posts: 24
  • 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");
}
 
author & internet detective
Posts: 38921
686
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: 24
  • 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.

 
Marshal
Posts: 67164
169
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!