Hello,
I have a weird problem with my validation in my input form. Instead of generating an alert (pop-up), I want to print a warning next to each box that causes an error. Imagine it is a from with multiple inputboxes that all have a similar check.
This is a script I use to verify if an inputbox 'naam' is filled in:
This function is called when the form is submitted (onsubmit), but also when focus changes away from this input box (onchange):
The behaviour is what I expect:
1. When the inputbox is not filled in, and one clicks 'submit', a message is printed next to the box.
2. The message stays until this field is filled in (one can leave the inputbox).
3. If one first fills in the name, the message disappears. However, if one then goes back to the inputbox and deletes everything, the message reappears when trying to leave the box (and one can't leave the box).
OK, so this works perfectly.
Now I wanted to check an entered emailadress on validity (simplistic check: either I expect there to be a @ sign in it, or the box to be empty). And here is my code:
Now, the behaviour is odd...
1. when it is not filled in, there is no problem (no message, ok).
2. when it is filled in (but not a valid emailaddress), there is message upon submit (ok) and the submit fails (ok). Now the user has 2 options: either fill in a correct address or delete what is in the box; he cannot leave the box until he does one of these two.
If he fills in a correct address the message disappears when focus moves away or the form is submitted (ok). However, If he clears the box, it is possible to move focus to another box, but the message stays... Submitting the form is possible.
How come the message stays ?
As a test case, I tried an inputbox which has to be left blank (it is just a test case). It should display a message when the box contains data, but not display that warning when it is emtpy... (using the onchange event: if the warning was there, it will not change even if the box is erased and focus is moved to another window) So here lies the problem I think...
Any ideas?
Thanks!
A long post... I wonder if anyone will have bothered to read it...
Jörg
I have a weird problem with my validation in my input form. Instead of generating an alert (pop-up), I want to print a warning next to each box that causes an error. Imagine it is a from with multiple inputboxes that all have a similar check.
This is a script I use to verify if an inputbox 'naam' is filled in:
Code:
function CheckNaam() { s=form1.naam.value; if (s=='') { e_naam.innerHTML="error: this is a required field"; event.returnValue=false; } else { e_naam.innerHTML=""; } }
This function is called when the form is submitted (onsubmit), but also when focus changes away from this input box (onchange):
Code:
<input type="text" name="naam" size="40" maxlength="256" value="" onchange="return CheckNaam()"> <div class="errormessage" id="e_naam"></div> </td></tr>
1. When the inputbox is not filled in, and one clicks 'submit', a message is printed next to the box.
2. The message stays until this field is filled in (one can leave the inputbox).
3. If one first fills in the name, the message disappears. However, if one then goes back to the inputbox and deletes everything, the message reappears when trying to leave the box (and one can't leave the box).
OK, so this works perfectly.
Now I wanted to check an entered emailadress on validity (simplistic check: either I expect there to be a @ sign in it, or the box to be empty). And here is my code:
Code:
function CheckEmail() { s=form1.email.value; if ((s.length>0) && (s.indexOf("@")<1)) { e_email.innerHTML="E-mail incorrect, leave blank if none"; event.returnValue=false;} else { e_email.innerHTML=""; } }
1. when it is not filled in, there is no problem (no message, ok).
2. when it is filled in (but not a valid emailaddress), there is message upon submit (ok) and the submit fails (ok). Now the user has 2 options: either fill in a correct address or delete what is in the box; he cannot leave the box until he does one of these two.
If he fills in a correct address the message disappears when focus moves away or the form is submitted (ok). However, If he clears the box, it is possible to move focus to another box, but the message stays... Submitting the form is possible.
How come the message stays ?
As a test case, I tried an inputbox which has to be left blank (it is just a test case). It should display a message when the box contains data, but not display that warning when it is emtpy... (using the onchange event: if the warning was there, it will not change even if the box is erased and focus is moved to another window) So here lies the problem I think...
Any ideas?
Thanks!
A long post... I wonder if anyone will have bothered to read it...
Jörg
Comment