okay this is quite simple i'm sure, but i can't manage to get it.
if somebody could just do stuff for something basic like this, so i can understand how on earth radio buttons are worked with:
there are 3 radio buttons for...say...marital status. when a button is clicked, just alert the status. i tried a script with all the combinations of ifs and elses and radio button names and ids i could think of. here's one of my tries.
<script>
function alertstatus(){
if (document.forms.form1.r[0].value=="yes"){
alert('single');
}
if(document.forms.form1.r[1].value=="yes"){
alert('married');
}
if (document.forms.form1.r[2].value=="yes"){
alert('divorced');
}
}
</script>
<body>
<form name="form1">
Your marital status:
<input type="radio" name="r" value="no"> Single
<input type="radio" name="r" value="no"> Married
<input type="radio" name="r" value="no"> Divorced
</form>
<BR>
<input type="button" value="submit" onClick="alertstatus()">
</body>
WHY doesn't it work??
when i use if-else, it always executes only the else phrase, no matter what button is checked. if i use only ifs, as above, nothing executes. i never managed to make anything work with if-else if-else. (maybe that's not the right syntax?)
if somebody could just do stuff for something basic like this, so i can understand how on earth radio buttons are worked with:
there are 3 radio buttons for...say...marital status. when a button is clicked, just alert the status. i tried a script with all the combinations of ifs and elses and radio button names and ids i could think of. here's one of my tries.
<script>
function alertstatus(){
if (document.forms.form1.r[0].value=="yes"){
alert('single');
}
if(document.forms.form1.r[1].value=="yes"){
alert('married');
}
if (document.forms.form1.r[2].value=="yes"){
alert('divorced');
}
}
</script>
<body>
<form name="form1">
Your marital status:
<input type="radio" name="r" value="no"> Single
<input type="radio" name="r" value="no"> Married
<input type="radio" name="r" value="no"> Divorced
</form>
<BR>
<input type="button" value="submit" onClick="alertstatus()">
</body>
WHY doesn't it work??

when i use if-else, it always executes only the else phrase, no matter what button is checked. if i use only ifs, as above, nothing executes. i never managed to make anything work with if-else if-else. (maybe that's not the right syntax?)
Comment