Page 1 of 1

javascript form flush fields - problem

Posted: Mon Aug 27, 2007 12:13 am
by dream2rule
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


[syntax="javascript"]
<script language="JavaScript">
function validateForm()
{
// check name
if (document.forms[0].elements[0].value == "")
{
alert ("Please enter a name!");
return false;
}
// check password length
if (document.forms[0].elements[1].value.length < 6)
{
alert ("Please enter a password 
of at least 6 characters!");
return false;
}
// check email address
// check age
if (isNaN(document.forms[0].elements[3].value))
{
alert ("Please enter a valid age!");
return false;
}
// check age range
if (parseInt(document.forms[0].elements[3].value) < 1 ||
parseInt(document.forms[0].elements[3].value) > 99)
{
alert ("Please enter a valid age!");
return false;
}
return true;
}
</script>
In the above code, if the name is checked once and then the password, the moment i leave the password field empty the error message is being displayed asking me to enter a password but when the alert box is clicked ok, all the values that i have entered in the form earlier disappear. How can i prevent this? I don't want to flush out the values if correct and if already entered.

Any help would be highly appreciated.

Thanks


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Aug 27, 2007 9:42 pm
by califdon
What is the code where your validateForm function is called?

Posted: Tue Aug 28, 2007 1:13 pm
by thewebdrivers
looks like your form is submitting and is not check return data.

Please double check that in your form tag you have

Code: Select all

onclick="return validateForm();"