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 variablei
- you taking
button
insidewhile
loop repeating checkboxes.
Comments
Post a Comment