checkbox validation using javasript

File name : index.php

<html>
<head>
<script LANGUAGE="JavaScript">
function ValidateForm(form){
ErrorText= "";
if ( ( form.gender[0].checked == false ) && ( form.gender[1].checked == false ) )
{
alert ( "Please choose your Gender: Male or Female" );
return false;
}
if (ErrorText= "") { form.submit() }
}
</script>
</head>
<body>
<form name="feedback" action="#" method=post>
Your Gender: <input type="checkbox" name="gender" value="Male"> Male
<input type="checkbox" name="gender" value="Female"> Female
<input type="button" name="SubmitButton" value="Submit" onClick="ValidateForm(this.form)">
<input type="reset" value="Reset">
</form>
</body>
</html>

File name : index.php

<!DOCTYPE html PUBLIC "-//ittutorialC//DTD XHTML 1.0 Transitional//EN" "http://www.ittutorial.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.ittutorial.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script language="JavaScript" type="text/javascript">
function checkscript() {
if (document.myform.box1.checked == true && document.myform.box2.checked == true)
{ alert('box1 & 2 are selected');
form.email.focus();
return false ;
}

// If the script makes it to here, everything is OK,
// so you can submit the form

else return true;
}

</script>
</head>

<body>

<form name="myform" action="" method="post" onsubmit="return checkscript()">


<input
type="checkbox"
name="box1"
value="yes1">
<input
type="checkbox"
name="box2"
value="yes2">
<input
type="submit">
</form>
</body>
</html>

File name : index.php

<script type="text/javascript">

function checkForm(form)
{

if(!form.terms.checked) {
alert("Please indicate that you accept the Terms and Conditions");
form.terms.focus();
return false;
}
return true;
}

</script>

<form onsubmit="return checkForm(this);">

<p><input type="checkbox" name="terms"> I accept the <u>Terms and Conditions</u></p>
<p><input type="submit"></p>
</form>


<form onsubmit="return checkForm(this);">
<p><input type="checkbox" required name="terms"> I accept the <u>Terms and Conditions</u></p>
<p><input type="submit"></p>
</form>



<style type="text/css">

input[type="checkbox"]:required:invalid + label { color: red; }
input[type="checkbox"]:required:valid + label { color: green; }

</style>

<form>
<p><input id="field_terms" type="checkbox" required name="terms">
<label for="field_terms">I accept the <u>Terms and Conditions</u></label></p>

</form>

File name : index.php

<form method="POST" action="">
<input type="checkbox" name="checkbox" value="check" />
<input type="submit" name="email_submit" value="submit"
onclick="if(!this.form.checkbox.checked){alert('You must agree to the terms first.');return false}" />
</form>





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here