mardi 13 septembre 2016

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

Below is the HTML/PHP code, in which i need to validate any of the checkbox out of 5 before submit the 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>



Aucun commentaire:

Enregistrer un commentaire