0
I am trying to validate a form. the user can only instill numeral values. I did it this way but it’s not working
function ValidateContactForm()
{
var year = document.ContactForm.year;
if (year.value == "")
{
isNaN( document.myForm.edition.value)
window.alert("Please enter year.");
year.focus();
return false;
}
}
code in HTML
<body>
<?php include 'addDataAdmin.php';?>
<form name="ContactForm" action="addDataAdmin.php" method="POST" enctype="multipart/form-data" autocomplete="off" onsubmit="return ValidateContactForm();">
ISBN:<input type="text" name="ISBN">
Author's Name:<input type="text" name="Authorsname">
Title:<input type="text" name="Title">
Edition:<input type="number" name="edition">
Year:<input type="number" name="year">
Category:
<select name="category" size="1">
<option value="computing">Computing</option>
<option value="Romance">Romance</option>
<option value="Fiction">Fiction</option>
<option value="Non-Fiction">Non-Fiction</option>
</select>
<br />
Publisher:<input type="text" name="publisher">
Quantity-in-stock:<input type="number" name="quantityinstock">
Price:<input type="number" name="price">
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit" formaction="/upload.php">
<input type="submit" value="Send" name="send">
<input type="reset" value="Clear">
</form>
</body>
</html>
You can put your HTML?
– Sergio
I reissued the answer to a function only validate the numeric fields
– user60252
put Alert in response
– user60252
Thanks Leo, I tested and it didn’t work after I saw that it is missing only one { in your code but otherwise all right!
– Diana Madeira