Hello, I’m creating a form which includes a file uploader and multiple checkboxes.
So far i’ve managed to validate the form using alert() but i would like to replace the alert message with an error message which displays on top of the form.
Here is what i have so far -
<script type="text/javascript">
function validateproject()
{
valid = true;
if(document.input.status.checked == false) {
alert ("Please select checkbox")
valid = false;
}
if(document.input.status2.checked == false) {
alert ("Please select the second checkbox")
valid = false;
}
if(document.input.uploaded.value == "")
{
alert ("Please attach a file to be uploaded")
valid = false;
}
return valid;
}
</script>
<body id="wrapper">
<form name="input" action="testvalidation.html" enctype="multipart/form-data" method="post" onsubmit="return validateproject();">
<table>
<tr>
<th>checkbox:</th>
<td>
<input class="uploadform" id="original" type="checkbox" name="status" value="true">please check this box<br >
</td>
</tr>
<tr>
<th>checkbox2:</th>
<td>
<input class="uploadform" id="original2" type="checkbox" name="status2" value="true">please check the second box<br >
</td>
</tr>
<tr>
<th>
Upload File
</th>
<td>
<input type="file" name="uploaded" id="uploaded">
</td>
</tr>
</table>
<br>
<input style='font-size:2em;' type="submit" value="Upload" name="upload">
</form>
</body>
Can anyone help me display the error messages?