Question

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.

Was it helpful?

Solution

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!');
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top