JavaScript에서 Radio Button 다루기
JavaScript에서 Radio Button 다루기
Radio Button 체크 여부 확인
js
function checkForm(){
var f = document.formname;
var checked = false;
for(i=0; i <f.Blood.length; i++){
if(f.Blood[i].checked) checked = true;
}
if(!checked){
alert('혈액형을 넣어주세요');
f.Blood[0].focus();
return false;
}
return true;
}
html
<form name="formname" onSubmit="return checkForm()">
<input type="radio" name="Blood" value="A"> A형
<input type="radio" name="Blood" value="AB"> AB형
<input type="radio" name="Blood" value="B"> B형
<input type="radio" name="Blood" value="O"> O형
<button type="submit">보내기</button>
</form>
See the Pen 자바스크립트 radio button 다루기 by younghyeong ryu (@wangta69) on CodePen.