I have built a spry widget form where the submit button is at the bottom of the page, and all my required fields are at the top of the page. The problem for a user is that when it is submitted and there is an error in a required field, it seems that nothing happens. Only by scrolling back up to the top of the page will they see the error field.
What I would like to do is test for the background color of the field and if it is not the good field color, then have an alert tell them which field is invalid.
The code I’m trying occurs on the submit operation.
My form is named addForm. Here is what I have.
<form method=”POST” action=”Admin/DataSave.html” name=”addForm” onSubmit=”return fieldErrors()”>
This is the function to run on the onSubmit.
The <span id for the field where you enter your name is sprytextfield1. If this field validates then it has the background color of #B8F5B1.
<script type=”text/javascript”>
<!–
function fieldErrors() {
var theBgd = document.getElementById(“sprytextfield1.style.backgroundColor.value”);
If(theBgd != “#B8F5B1”)
alert(“Oops, there is an error with your name.”);
return false;
}
//–>
</script>
Where am I going wrong?
I’m a newbee to scripting.
Thanks for any help.