I want when checked any checkbox , then it should gives a error message for all details(textbox and dropdown list) inside checked checkbox. In code if I select 1st checkbox then wants to do validation to fill textbox and dropdown list value, until it don't check another options ,& same with all checkbox. I don't know to do. can anyone please tell me how to do this.
<script>
function validate()
{
document.getElementById("error").innerHTML="atleast check one checkbox.";
//alert("");
var chk=document.getElementsByName("chkbox");
var hasChecked = false;
for(var i=0; i<chk.length; i++)
{
if(chk[i].checked)
{
hasChecked= true;
break;
}
}
return true;
}
function toggle(source) {
checkboxes = document.getElementsByName('a[]');
for(var i=0, n=checkboxes.length;i<n;i++)
{
checkboxes[i].checked = source.checked;
}
}
</script>
</head>
<body>
<form method="post" name="form">
<table>
<tr><td><div id="error"></div></td></tr>
<tr><td style="padding:10px;padding-top:0; padding-bottom:0" >1 .What does the scope of test include?</td></tr>
<tr><td style="padding-left:5%;padding-bottom:0"><input type="checkbox" name="a[]" value="a) selected 1"> a)select 1<br /><br />
Name : <input type="text" name="fname" /><br /><br />
Country : <select><option value="1">india</option><option value="2">usa</option></select>
</td></tr>
<tr><td style="padding-left:5%;padding-bottom:0"><input type="checkbox" name="a[]" value="b) selected 2"/> b)select 2</td></tr>
<tr><td style="padding-left:5%;padding-bottom:0"><input type="checkbox" name="a[]" value="c)selected 3"/> c select 3</td></tr>
<tr><td style="padding-left:5%;padding-bottom:0"><input type="checkbox" name="a[]" value="d)selected 4"/> d)select 4</td></tr>
<tr><td style="padding-left:5%;padding-bottom:0"><input type="checkbox" name="a[]" onClick="toggle(this)" value="e)Or all of the above"/> e)Or all of the above </td></tr>
</table>
<input type="submit" onclick="validate()" name="submit" value="Submit" />
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$a=@$_POST['a'];
$supplies = @implode(',',$_POST['a']);
echo $supplies;
}
?>
Aucun commentaire:
Enregistrer un commentaire