-1

Can somebody please help me to create a mandatory radio button in JSP?

Idea is to prompt the user to check the radio box when he parses through the page, and once he checks either of the radio button (Yes or No) we capture the value and save it to Db.

By default radio should be blank it should be blank.

Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
Harshil Shah
  • 13
  • 3
  • 7
  • 1
    You are expected to attempt a solution and show us what you have tried; then ask a specific question if you don't understand something. Please read the [FAQ] and [Ask]. – Jim Garrison Feb 11 '14 at 06:07
  • 1
    @JimGarrison i know the rules but am just a newbie to JSP so have no clue...Basically what i am trying is add a hidden radio button by default checked and it will be hidden, when a user comes across that radio button i will show an alert to check the radio and just capture the value in my table as to whatever user selected(Yes or NO). – Harshil Shah Feb 11 '14 at 06:12

1 Answers1

0

Embedded a piece of Javascript in your page, upon form submission, the Javascript validates radiobutton value like this:

How can I check whether a radio button is selected with JavaScript?

if(document.getElementById('gender_Male').checked) {
  //Male radio button is checked
} else if(document.getElementById('gender_Female').checked) {
  //Female radio button is checked
} else {
    alert('You should select a radio button!');
}
Community
  • 1
  • 1