dreamwest Posted February 29, 2012 Share Posted February 29, 2012 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 »' /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/258006-radio-check/ Share on other sites More sharing options...
sunfighter Posted March 1, 2012 Share Posted March 1, 2012 <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> Quote Link to comment https://forums.phpfreaks.com/topic/258006-radio-check/#findComment-1322794 Share on other sites More sharing options...
dreamwest Posted March 2, 2012 Author Share Posted March 2, 2012 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 »' /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/258006-radio-check/#findComment-1323036 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.