I have form which is Dynamically populated from the data base as below
<form name="marksForm" method="post" action="process_add_marks.php">
<table width="800px" class="tbl">
<tr><th><b>Name</b></th><th><b>University</b></th><th><b>Batch</b></th><th><b>Contact</b></th><th><b>Add Marks</b></th></tr>
<?php
$query = "SELECT sl_no,student_name,university,batch,contact FROM mytable WHERE `university` = '".$clgname."' AND `batch` = '".$batch."' AND delete_status != 'Deleted'";
$raw_result = mysqli_query($link,$query)or die(mysqli_error());
$count=mysqli_num_rows($raw_result);
if(mysqli_num_rows($raw_result)>0)
{
while($results = mysqli_fetch_array($raw_result))
{
echo "<tr>";
echo "<td>".$results['student_name']."</td>";
echo "<td>".$results['university']."</td>";
echo "<td>".$results['batch']."</td>";
echo "<td>".$results['contact']."</td>";
echo "<td><input name=marks[".$results['sl_no']."] style='width:30px' type='text'></td>";
echo "</tr>";
}
}
?>
</table>
<p id="markserr" style="color: #FF0000"></p>
<input type="hidden" name="hisdl" value="<?=$sdlname?>">
<input style="margin: 20px;cursor: pointer;" name="submit" type="submit" class="button" onclick="return validateMarks();">
</div>
</form>
I'm trying to validate input field using javascript as below
function validateMarks()
{
var b=document.getElementsByTagName('input');
var count=0;
for (i=0;i<b.length;i++){
var box=b[i];
if( box.value!=''){
count++;
break;
}
}
if (count!=0){
alert('Please fill all the fields');
return false;
} else {
return true;
}
}
The problem is I'm not able to submit the form even after filling all input fields
requiredattribute insteadinputsinside the formconsole.log(count);after for loop inside function and check your browser's console.widthattribute does not have units; also, be modern, use CSS instead of attributes.