javascript - HTML how to validate any of checkbox which are in Array before submit -


below html/php code, in need validate of checkbox out of 5 before submit form.

function checkaddress(checkbox)  {      if (checkbox.checked)      {  document.frmuser.action = "edit_user.php";  document.frmuser.submit();      }    else {alert("checkbox");}  }
<!doctype html>  <head>  <meta charset="utf-8">  <title>details form</title>  <script language="javascript" type="text/javascript">    function checkaddress(checkbox)  {      if (checkbox.checked)      {  document.frmuser.action = "edit_user.php";  document.frmuser.submit();      }    else {alert("checkbox");}  }  </script>        </head>    <body>    <div class="form-style-1">  <form name="frmuser" method="post" action="">  <?php  i=0;  while(i=5){  ?>  <input type="checkbox" name="users[]" value="<?php echo i; ?>" >  <input type="button" name="update" class="button" value="update" onclick="checkaddress(this);" />  <?php  $i++;}  ?>  </form></div></body></html>

i think trying this

function checkaddress(checkbox) {    if (checkbox.checked) {      document.frmuser.action = "edit_user.php";      //document.frmuser.submit();    } else {      document.frmuser.action = "#";      alert("checkbox");    }  }
<div class="form-style-1">    <form name="frmuser" method="post" action="">      <?php $i=0; while($i<=5){ ?>      <input type="checkbox" name="users[]" onclick="checkaddress(this);" value="<?php echo $i; ?>">        <?php $i++;} ?>      <input type="submit" name="update" class="button" value="update" />    </form>  </div>

some errors in code

  • you have not used $ while denoting variable i
  • you taking button inside while loop repeating checkboxes.

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -