I want to make a code if you put your resident registration number(7 numbers) in the text box and press the result button, automatically checks the gender according to the first number(1,3 = check male/ 2,4 = check female). But if I press the result button, the radio check will blink once and disappear. What should I do?
<form action="#" name="idForm">
<fieldset>
<legend>gender check</legend>
<input type="text" name="idNumber" maxlength="7" id="num">
<label for="num"> : 7 numbers</label>
<button name="result">result</button>
<input type="radio" id="male" name="gender">
<label for="male">man</label>
<input type="radio" id="female" name="gender">
<label for="female">woman</label>
</fieldset>
</form>
<script>
var idNumber = document.idForm.idNumber;
var result = document.idForm.result;
var male = document.getElementById('male');
var female = document.getElementById('female');
result.onclick = function(){
var v = idNumber.value;
if(v.length == 7){
if(v.charAt(0) == 1 || v.charAt(0) == 3){
male.checked=true;
}else if(v.charAt(0) == 2 || v.charAt(0) == 4){
female.checked=true;
}else{
alert('! : 7 numbers');
}
}else{
alert('! : 7 numbers');
}
};
</script>