Click to See Complete Forum and Search --> : form validation routine


janice
09-05-2003, 11:48 AM
I have a long asp page coded to client's spec.
The problem with this page is to determine that a box is blank, the entire form is usually completed first.
They have found that this is cumbersome and frustrating so they have asked me to put a trigger or an event handler that will prevent a user from leaving some textboxes before data is entered into that text box.
I have several onSubmit() javascript codes but they don't solve the problem because the client is still dealing with having to complete entire form before finding that an error exists.
Can someone give me a link or a help on the code that prevents a user from leaving an input textbox until value is entered into that textbox, please?
Thanks for your assistance in advance.

Charles
09-05-2003, 12:16 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>

<script type="text/javascript">
<!--
current = 0;
last = 3;
function check() {
var f = document.forms[0];
if (/\S/.test(f.elements[current].value)) {
if (current < last) {
f.elements[++current].onblur = check;
f.elements[current].focus();
}
}
else {f.elements[current].focus()}
}
// -->
</script>

<form action="">
<div>
<label>Fee<input type="text" onblur="check()"></label>
<label>Fie<input type="text"></label>
<label>Foe<input type="text"></label>
<label>Fum<input type="text"></label>
<button type="submit">Submit</button>
</div>
</form>

janice
09-05-2003, 12:37 PM
You must belong to a rapid response team.
Thank you for the quick response.
The code isn't working as well as I want it to work.
First, not all fields are mandatory.
Infact there are a total of 8 fields that are mandatory.
What is happening so far is that it focuses on the first blank field (this is good) but once that textbox is filled, it doesn't work anymore.