Jump to content

radio check


dreamwest

Recommended Posts

I want to check if a radio button has been selected, but the following doesnt work.

 

<form name='x'>
<input type="radio" name="type" value='1'  /> Renovation <br>
<input type="radio" name="type" value='2'  /> Buy and hold (Rental)<br>
<input type="radio" name="type" value='3'  /> Development <br>
<br />
<input type='button' onclick="if(document.x.type.checked == false) { alert('Select a Property Type'); } else { alert('Checked'); }" value='Continue &#187;' />
</form>

Link to comment
https://forums.phpfreaks.com/topic/258006-radio-check/
Share on other sites

<form name='x'>
<input type="radio" name="type" value='1'  /> Renovation <br>
<input type="radio" name="type" value='2'  /> Buy and hold (Rental)<br>
<input type="radio" name="type" value='3'  /> Development <br>
<br />
<input type='button' onclick="check();" value="click">
</form>
<div id="di"></div>
<script type="text/javascript">
function check()
{
doubleck = 0;
    var radio = document.getElementsByName('type');
    for (var i = 0; i < radio.length; i++)
    {
        if (radio[i].checked)
	{
        	alert(radio[i].value);
		doubleck = 1;
    }
}
if(doubleck == 0){
	alert('Nothing has been checked');
}
}
</script>

Link to comment
https://forums.phpfreaks.com/topic/258006-radio-check/#findComment-1322794
Share on other sites

Thanks. I used a id instead.

 

<form name='x'>
<input type="radio" name="type" value='1' id='T1'  /> Renovation <br>
<input type="radio" name="type" value='2' id='T2'  /> Buy and hold (Rental)<br>
<input type="radio" name="type" value='3' id='T3'  /> Development <br>
<br />
<input type='button' onclick="if(!document.getElementById('T1').checked && !document.getElementById('T2').checked && !document.getElementById('T3').checked) { alert('Select a Property Type'); } else { alert('ok'); }" value='Continue &#187;' />
</form>

Link to comment
https://forums.phpfreaks.com/topic/258006-radio-check/#findComment-1323036
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.