Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.