0

Hi all.

I have some problems with radio buttons. Hope to get some help here. Thanks in advance.

Here's the html:

<?php while($row=mysql_fetch_array($result)) { ?>
         <input name="replacement" id="replacement" type="radio"
            value="<?php echo  $row['date']; echo $row['title']; ?>"

I need to validate if none of the radio buttons is checked using javascript. How can I do that? Any help will be appreciated. =)

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by lcyew
0
for (i=0, n=theForm.radio_btn_name.length; i<n; i++) {
        if (theForm.radio_btn_name[i].checked) {
            var checkvalue = theForm.radio_btn_name[i].value;
            break;
        } 
    }
0

I've solved the problem using codes below:

function validateCB(theName){
   var counter=0;
   var cb=document.getElementsByName(theName)
   for (i=0; i<cb.length; i++) {
        if((cb[i].tagName=='INPUT')&&(cb[i].type=='radio')){
          if (cb[i].checked)
             counter++;
        }
   }
   if (counter==0) {  
   return false;
  }
return true;
}

function check(){

	
	if (!validateCB('replacement')) {
   		alert("Please fill in all the fields marked with *");
   		return false;
	 }
         return true;
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.