Associate
I have written the following block of code, which cycles through each element on a form, stopping to alert individually, which fields contain 0 characters or a null value.
How can I amend this to record the details for each field missing data and display one alert box at the end with each error on a new line?
Hope this makes sense.
I had a go, but could only get the first error message into the array I created.
Code:
for(var i = 0; i < form.elements.length; i++){
if(form.elements[i].value.length == 0 || form.elements[i].value == "null"){
alert('No value entered in '+form.elements[i].name+' field.');
form.elements[i].focus();
return false; //form has errors halt submit to server
}
}return true; //all fields are completed appropriately
Hope this makes sense.
I had a go, but could only get the first error message into the array I created.
Last edited: