[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
[mv] Using JavaScript to validate a form
****** message to minivend-users from Brian Wright <bdw@Aturna.com> ******
Hello, listees. :)
I'm trying to use JavaScript to validate and submit a form. However, the alert
box does not pop up if you omit a field. Here's a code snippet:
[set NewAccount]
[userdb function=new_account ignore_case=1]
[if session failure]
[data session failure]
[else]
[userdb save]
[tag export userdb userdb.asc]Proceed[/tag]
[/else]
[/if]
[/set]
<SCRIPT LANGUAGE="JavaScript">
<!--
function validateForm(form)
{
if (form.name.value == "")
{
alert("You have not filled in the Name field.");
form.name.focus();
return false;
}
else if (form.address.value == "")
{
alert("You have not filled in the Address field.");
form.address.focus();
return false;
}
else if (form.city.value == "")
{
alert("You have not filled in the City field.");
form.city.focus();
return false;
}
else if (form.state.value == "")
{
alert("You have not filled in the State field.");
form.state.focus();
return false;
}
else if (form.zip.value == "")
{
alert("You have not filled in the Zip field.");
form.zip.focus();
return false;
}
else if (form.email.value == "")
{
alert("You have not filled in the E-mail field.");
form.email.focus();
return false;
}
else if (form.phone_day.value = "")
{
alert("You have not filled in the Daytime Phone field.");
form.phone_day.focus();
return false;
}
}
-->
</SCRIPT>
<form ACTION="[process-target secure=1]" METHOD="POST">
<input TYPE="hidden" NAME="mv_check" VALUE="NewAccount">
<input TYPE="hidden" NAME="mv_doit" VALUE="return">
<input TYPE="hidden" NAME="function" VALUE="new_account">
<INPUT TYPE=hidden NAME="mv_nextpage" VALUE="[data session prev_url]">
(form fields here)
Then, I use the following to submit:
<INPUT TYPE=submit VALUE="Create Account" SIZE=10 onSubmit="if
(validateForm(this.form)){this.form.submit()}">
But, it doesn't catch an empty form field. :(
--Brian
_________________________________________________________________________
Brian Wright Aturna Communications Inc.
bdw@aturna.com Internet Services
WWW http://www.aturna.net
_________________________________________________________________________
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list