Akopia Akopia Services

[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 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


Search for: Match: Format: Sort by: