php - How not to submit a form if no radio button is checked -


i using php in order create html form.
form has 3 radio buttons , submit button.
in initial state of form, none of radio buttons checked.
want make form not submitted if non of radio buttons checked.
there way that? attached part of php code.

    for($i=0; $i<$nchoices; $i++) { $text='<input type="radio" name="answer" value="' . $idchoices[$i] . '"'; $text.=">  ". $choices[$i] . "</input>"; $choiceoutput.= $text."<br /><br />"; } 

thanks!

this javascript can used simple client-side validation. it's not considered safe validate on client-side if purpose see if user selected value do. otherwise further validation needs taking place in php script.

<script type="text/javascript"> function validate() {   var retval = false;   (var i=0; < document.myform.r.length; i++)   {     if (document.myform.r[i].checked)     {       retval = true;     }   }      return retval; } </script>

simple form putting work.

<form name="myform" action="page.php" onsubmit="return validate()" method="post"> <input type="radio" id="r"> <input type="radio" id="r"> <input type="submit" value="ok"> </form>

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -