문제

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.

도움이 되었습니까?

해결책

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!');
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top