I have the following script:
[CODE]function validateForm()
{
var form = document.getElementById(“productform”)
var elementNum = 12
var errorString = “You have not filled in the following fields:n”
var i
var error = false
for(i=0;i<elementNum;i++)
{
if (document.forms[0].elements[i].value == “”)
{
errorString = errorString + ” – ” + document.createproductfrm.elements[i].name + “n”
error = true
}
}
if (error == true)
{
window.alert(errorString)
return false;
}
else
{ return true; }
}
When creating a product on my page, the script goes through the input boxes and makes sure a value is present. This works fine.
However, I am currently using the same script to validate input boxes when I update a product. When updating a product, my background PHP puts the current details from the database into the text boxes on the form.
My script does not recognise when a value has been deleted from a text box by a user. Although when viewing in the browser, the box appears blank, the value of the box is still present in HTML (because it was set my PHP code). Because the value is not “”, my script thinks everything is ok, even though the user has left a field blank. Any suggestions?