1
I’m trying to validate a <form>
with Javascript, but the code I created is not doing anything. seems right to me.
HTML code
<form name="ContactForm" action="addDataAdmin.php" method="POST" enctype="multipart/form-data" autocomplete="off" onsubmit="return ValidateContactForm();">
<p>ISBN</p> <input type="text" name="ISBN">
<p>Author's Name</p> <input type="text" name="Authorsname">
<p>Title</p> <input type="text" name="Title">
<p>Edition</p> <input type="text" name="edition">
<p>Year</p> <input type="text" name="year">
<p>Category</p>
<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 />
<p>Publisher</p> <input type="text" name="publisher">
<p>Quantity-in-stock</p> <input type="text" name="quantityinstock">
<p>Price</p> <input type="text" 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>
Script
function ValidateContactForm()
{
var ISBN = document.ContactForm.ISBN;
var Authorsname = document.ContactForm.Authorsname;
var Title = document.ContactForm.Title;
var edition = document.ContactForm.edition;
var year= document.ContactForm.year;
var category = document.ContactForm.category;
var publisher = document.ContactForm.publisher;
var quantityinstock= document.ContactForm.quantityinstock;
var price = document.ContactForm.price;
}
if (ISBN.value == "")
{
window.alert("Please enter ISBN.");
ISBN.focus();
return false;
}
Thanks jbueno ta working :)
– Diana Madeira
@Dianamadeira At your service
– Jéf Bueno
jbueno, if I just want numbers to be entered in the textbox do it this way ? if (year.value == "") { isNaN( Document.myForm.Edition.value) window.Alert("Please enter year."); year.Focus(); Return false; }
– Diana Madeira
Well, there are some better ways to do that, @Dianamadeira
– Jéf Bueno
If you like, you can open another question specifically about this.
– Jéf Bueno