form validation then action

Discussion in 'Javascript' started by dougawells@gmail.com, Apr 3, 2006.

  1. Guest

    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?
    , Apr 3, 2006
    #1
    1. Advertising

  2. VK Guest

    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.
    VK, Apr 3, 2006
    #2
    1. Advertising

  3. Guest

    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; ...

    ??
    , Apr 4, 2006
    #3
  4. Lee Guest

    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.


    --
    Lee, Apr 4, 2006
    #4
  5. Guest

    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>
    , Apr 4, 2006
    #5
  6. Guest

    I tried return; return (true); return ("true"); return (0); all with
    the same result - the CGI never gets called.
    , Apr 4, 2006
    #6
  7. Evertjan. Guest

    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)
    Evertjan., Apr 4, 2006
    #7
  8. Lee Guest

    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;


    --
    Lee, Apr 4, 2006
    #8
  9. Guest

    Thank you
    , Apr 6, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Bloggs
    Replies:
    1
    Views:
    719
    Sudsy
    Aug 3, 2003
  2. John
    Replies:
    0
    Views:
    843
  3. Replies:
    7
    Views:
    602
  4. Replies:
    0
    Views:
    258
  5. mikew01

    Change form action then back again

    mikew01, Jan 15, 2009, in forum: Javascript
    Replies:
    1
    Views:
    134
    Thomas 'PointedEars' Lahn
    Jan 15, 2009
Loading...

Share This Page