[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] Using JavaScript to validate a form
****** message to minivend-users from Brian Wright <bdw@aturna.com> ******
I attempted to post the code for the form, but it was mangled on transit It
doesn't catch errors. Here it is:
<HTML>
<HEAD>
<TITLE>CyberFlicks -- Create a new account</TITLE>
</HEAD>
<BODY background="/cyberflicks/images/gamestile.gif">
<H1 align="center">Create an account at CyberFlicks</H1>
[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">
<!-- Hide code from non-js browsers
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 Zip 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;
}
[if data failure]
alert("[data session failure]");
[/if]
}
// end hiding -->
</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]">
<TABLE WIDTH=600 ALIGN="center">
<TR><TD>
<TABLE WIDTH=600><TR><TD __HEADERBG__>
<FONT SIZE="+2" COLOR="__HEADERTEXT__">Shipping Address</FONT>
</TD></TR></TABLE>
<TABLE BORDER=0 WIDTH=600>
<TR>
<TD ALIGN=RIGHT>
<IMG WIDTH=12 HEIGHT=12 SRC="redball.gif">
</TD>
<TD ALIGN=RIGHT><B>Name</B></TD>
<TD>
<INPUT TYPE="text" NAME="name" VALUE="[value name]" size=40>
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT>
<IMG WIDTH=12 HEIGHT=12 SRC="redball.gif">
</TD>
<TD ALIGN=RIGHT><B>Address</B></TD>
<TD ALIGN=LEFT>
<INPUT TYPE="text" NAME="address" VALUE="[value address]"
size=40>
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT>
<BR>
<IMG WIDTH=12 HEIGHT=12 SRC="redball.gif">
</TD>
<TD ALIGN=RIGHT><BR><B>City</B></TD>
<TD VALIGN=BOTTOM>
<TABLE CELLPADDING=0 MARGINWIDTH=0>
<TR>
<TD VALIGN=BOTTOM>
<INPUT TYPE="text" NAME="city" VALUE="[value city]" size=20>
</TD>
<TD ALIGN=RIGHT>
<BR>
<IMG WIDTH=12 HEIGHT=12 SRC="redball.gif">
</TD>
<TD ALIGN=CENTER VALIGN=BOTTOM>
State/Province<BR>
<INPUT TYPE="text" NAME="state" VALUE="[value state]" size=8>
</TD>
<TD ALIGN=RIGHT>
<BR>
<IMG WIDTH=12 HEIGHT=12 SRC="redball.gif">
</TD>
<TD ALIGN=CENTER VALIGN=BOTTOM>
Zip/Postal Code<BR>
<INPUT TYPE="text" NAME="zip" VALUE="[value zip]" size=10>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT>
<IMG WIDTH=12 HEIGHT=12 SRC="redball.gif">
</TD>
<TD ALIGN=RIGHT><B>Email Address</B></TD>
<TD ALIGN=LEFT>
<INPUT TYPE="text" NAME="email" VALUE="[value email]" size=40>
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT>
<IMG WIDTH=12 HEIGHT=12 SRC="redball.gif">
</TD>
<TD ALIGN=RIGHT>
<B>Country</B>
</TD>
<TD>
<SELECT MV="loop"
MV.PREPEND="[sort country:name]"
MV.SEARCH="ra=yes/fi=country.asc/ml=1000"
MV.OPTION="country"
NAME="country">
<OPTION VALUE="[loop-code]"> [loop-data country name]
</SELECT>
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT>
<IMG WIDTH=12 HEIGHT=12 SRC="redball.gif">
</TD>
<TD ALIGN=RIGHT><B>Daytime Phone</B></TD>
<TD>
<TABLE>
<TR>
<TD>
<INPUT TYPE="text" NAME="phone_day" VALUE="[value phone_day]"
size=16>
</TD>
<TD ALIGN=RIGHT>
</TD>
<TD ALIGN=RIGHT>
<B>Evening</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="phone_night" VALUE="[value
phone_night]" size=16>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT>
<IMG WIDTH="12" HEIGHT="12" SRC="redball.gif">
</TD>
<TD ALIGN=RIGHT><B>Username</B></TD>
<TD>
<TABLE>
<TR>
<TD><INPUT NAME=mv_username VALUE="[value mv_username]"
SIZE=10></TD>
<TD ALIGN=RIGHT>
<IMG WIDTH=12 HEIGHT=12 SRC="redball.gif">
</TD>
<TD><B>Password</B></TD>
<TD><INPUT TYPE=password NAME=mv_password VALUE="" SIZE=10>
</TD>
<TD><B>Verify</B></TD>
<TD><INPUT TYPE=password NAME=mv_verify VALUE="" SIZE=10>
</TD>
</TR>
</TR>
</TABLE>
<TR>
<TD ALIGN=RIGHT>
<IMG WIDTH="12" HEIGHT="12" SRC="redball.gif">
</TD>
<TD COLSPAN=2>
<I>Mandatory fields</I>
</TD>
</TR>
</TABLE>
</TR>
</TABLE>
<TABLE WIDTH=600 ALIGN="CENTER"><TR><TD __HEADERBG__>
<FONT SIZE="+2" COLOR="__HEADERTEXT__">Billing Address (if different)</FONT>
</TD></TR></TABLE>
<TABLE WIDTH=600 ALIGN="CENTER">
<TR>
<TD ALIGN=RIGHT><B>Name</B></TD>
<TD>
<INPUT TYPE="text" NAME="b_name" VALUE="[value b_name]" size=40>
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT><B>Address</B></TD>
<TD ALIGN=LEFT>
<INPUT TYPE="text" NAME="b_address" VALUE="[value b_address]"
size=40>
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT><B>City, State, Postal Code</B></TD>
<TD ALIGN=LEFT>
<INPUT TYPE="text" NAME="b_city" VALUE="[value b_city]" size=40>
</TD>
</TR>
</TABLE>
<TABLE ALIGN=CENTER WIDTH=600>
<TR><TD><HR></TD></TR>
<TR><TD ALIGN="LEFT">
<INPUT TYPE=submit VALUE="Create Account" onFocus="validateForm(this.form)"
SIZE=10> <INPUT TYPE=reset VALUE="Reset Form" size=10>
</TD></TR>
<TR><TD><HR></TD></TR>
</TABLE>
</FORM>
<P>
<!-- current page: @@MV_PAGE@@ -->
<!-- prev page: [data session prev_url] -->
</BODY>
</HTML>
On 21-Mar-2000 Ed LaFrance wrote:
> ****** message to minivend-users from Ed LaFrance
> <edlafrance@printexusa.com> ******
>
> Brian -
>
> I have done something similar, but when making the call to the Javascript I
> just used:
>
> <INPUT TYPE=submit VALUE="Whatever" onfocus="myscript(this.form)">
>
> When the user clicks the button, it receives focus just before the form is
> submitted. If any of the tests in the Javascript fail, the form is never
> submitted; the error message is displayed and focus returns to the assigned
> element. If there is no failure, the submit action is executed.
>
> I don't know if this is "proper" Javascript but it works for me. Perhaps
> it will work in your case as well.
>
> - Ed L.
>
> At 04:52 PM 3/20/00 -0800, you wrote:
>>****** 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
>
> Printex Marking Technologies
> 12113 Kirkham Rd.
> Poway, CA 92064 U.S.A.
> 858-513-2418
> 800-982-1928
> 858-513-2419 FAX
> http://www.printexusa.com
>
> -
> 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
_________________________________________________________________________
Brian Wright Aturna Communications Inc.
bdw@aturna.com Internet Services
AIM: BigBY2K ICQ: 21221328 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