Click to See Complete Forum and Search --> : OnBlur error... how to overcome


zulu99
01-04-2003, 04:24 AM
Hi

I have a form which we use for creating reports within our organisation. I have used certain javascript validations such as checking for null values, numeric values & dates.
The form will be pretty big one & the user has to enter around 50 to 60 values.
I have used all these validations on the OnBlur event.
the probelm is say
when the user moves to the 2nd field without entering any data in the first field he gets an error message say column cant be null then if the user tries to move back to the 1st column he is prompted with the message cannot leave 2nd column null & the browser hangs in the sense the user will keep on getting error messages infinitely.

I have no other option but to press CTRL - ALT - DEL at this stage.
How do i overcome this error.

Kindly reply

Sushant

Rick Bull
01-04-2003, 06:31 AM
Why don't you use the onsubmit event-handler of the form isntead, and return false if there is an error, like:


<script type="text/javascript" defer="defer"><!--
function focusElement(element, errorMsg) {
if (errorMsg != null) alert(errorMsg);
if (element.focus) element.focus();
if (element.select) element.select();
return false;
}
function validateForm(formElement) {
if (formElement.name.value == '')
return focusElement(formElement.name, 'Please enter a name');
if (formElement.age.value == '')
return focusElement(formElement.age, 'Please enter an age');
return true;
}
//--></script>
<form action="..." onsubmit="return validateForm(this);"><p>
Name: <input name="name" />
Age: <input name="age" />
<input type="submit" />
</p></form>

khalidali63
01-04-2003, 07:37 AM
Try this script,if the length >0 then perform your rest of the conditions,I am prety sure it will take care of your problem..Else you want to look at your conditions..

cheers

Khalid


<script>

function processForm(obj){
var ob = eval('document.frm.'+obj.name);
var field = ob.value;
if(field.length>0){
//perform rest of your conditions here
alert(field)
}
}
</script>
</head>
<body>
<form name="frm">
<input type="text" name="t1" onblur="processForm(this);">
<input type="text" name="t2" onblur="processForm(this);">
</form>