Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > form validation then action

Reply
Thread Tools

form validation then action

 
 
dougawells@gmail.com
Guest
Posts: n/a
 
      04-03-2006
I'm not figuring this probably simple thing out.

I've got a form that when submitted takes an action to a Perl
script..."...formsubmit.pl".

I want to be able to validate some fields, so put an onSubmit fall in
the <form> tag. Problem is, that if the form validates fine, the action
never takes place.

What am i missing?

 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      04-03-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I'm not figuring this probably simple thing out.
>
> I've got a form that when submitted takes an action to a Perl
> script..."...formsubmit.pl".
>
> I want to be able to validate some fields, so put an onSubmit fall in
> the <form> tag. Problem is, that if the form validates fine, the action
> never takes place.
>
> What am i missing?


To return true from onsubmit handler.
<form action="foo.cgi" onsubmit="return validate(this)">
where function validate returns either true or false.

 
Reply With Quote
 
 
 
 
dougawells@gmail.com
Guest
Posts: n/a
 
      04-03-2006
That's what i thought, but it doesn't seem to be working. I have the
<form onSubmit="return formValidate();" action="sendmyform.pl">

function formValidate() {

if (field is empty) {alert & then send focus to field in question}

}

This works if I have a problem field - I get an alert and return focus
to that field. But, I never execute the CGI, no matter what. I tried
return (true). I tried return; ...

??

 
Reply With Quote
 
Lee
Guest
Posts: n/a
 
      04-03-2006
(E-Mail Removed) said:
>
>That's what i thought, but it doesn't seem to be working. I have the
><form onSubmit="return formValidate();" action="sendmyform.pl">
>
>function formValidate() {
>
>if (field is empty) {alert & then send focus to field in question}
>
>}
>
>This works if I have a problem field - I get an alert and return focus
>to that field. But, I never execute the CGI, no matter what. I tried
>return (true). I tried return; ...
>
>??


Post a link to your page or the smallest subset of the code that
demonstrates the problem. You've got an error somewhere.


--

 
Reply With Quote
 
dougawells@gmail.com
Guest
Posts: n/a
 
      04-04-2006
This is my form validation subroutine:

function validateForm() {

if (window.document.ticket_form.name.value == 0 ||
window.document.ticket_form.name.value == "") {
alert ("You must enter your name");
window.document.ticket_form.name.focus();
return;
}
if (window.document.ticket_form.cc_num.value == 0 ||
window.document.ticket_form.cc_num.value == ""){
alert ("You must enter a credit card number");
window.document.ticket_form.cc_num.focus();
return;
}
if (window.document.ticket_form.phone.value == 0 ||
window.document.ticket_form.phone.value == ""){
alert ("You must enter a phone number");
window.document.ticket_form.phone.focus();
return;
}

return;
}

my HTML form line is:

<form name="ticket_form" onSubmit="return validateForm();"
action="/cgi-bin/form2file?ticket-template" method=post>

 
Reply With Quote
 
dougawells@gmail.com
Guest
Posts: n/a
 
      04-04-2006
I tried return; return (true); return ("true"); return (0); all with
the same result - the CGI never gets called.

 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      04-04-2006
(E-Mail Removed) wrote on 04 apr 2006 in comp.lang.javascript:

> I tried return; return (true); return ("true"); return (0); all with
> the same result - the CGI never gets called.


How should we know what you are talking about?

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers. <http://www.safalra.com/special/googlegroupsreply/>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Lee
Guest
Posts: n/a
 
      04-04-2006
(E-Mail Removed) said:
>
>This is my form validation subroutine:
>
>function validateForm() {
>
> if (window.document.ticket_form.name.value == 0 ||
>window.document.ticket_form.name.value == "") {
> alert ("You must enter your name");
> window.document.ticket_form.name.focus();
> return;
> }
> if (window.document.ticket_form.cc_num.value == 0 ||
>window.document.ticket_form.cc_num.value == ""){
> alert ("You must enter a credit card number");
> window.document.ticket_form.cc_num.focus();
> return;
> }
> if (window.document.ticket_form.phone.value == 0 ||
>window.document.ticket_form.phone.value == ""){
> alert ("You must enter a phone number");
> window.document.ticket_form.phone.focus();
> return;
> }
>
> return;
>}
>
>my HTML form line is:
>
><form name="ticket_form" onSubmit="return validateForm();"
>action="/cgi-bin/form2file?ticket-template" method=post>


All of your returns except the last one should be:
return false;
The last one should be:
return true;


--

 
Reply With Quote
 
dougawells@gmail.com
Guest
Posts: n/a
 
      04-06-2006
Thank you

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change form action then back again mikew01 Javascript 1 01-15-2009 01:27 PM
Struts: 1 action, 1 Form, several views handled by 1 only action. Any idea for better design? John Java 0 06-26-2007 11:22 PM
Help. SessionID is x then y then x then y BodiKlamph@gmail.com ASP General 0 09-03-2005 03:02 PM
javascript form validation - form action to another asp page iam247@gmail.com ASP General 7 08-20-2005 10:06 PM
Struts Static Action Form vs Dyanamic Action Form Joe Bloggs Java 1 08-03-2003 02:30 AM



Advertisments