Form Issue - onSubmit canceling Action

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bonus

    Form Issue - onSubmit canceling Action

    Im new at Javascripting and jumped in the ocean and Im a little lost,
    I am trying to get a form to do 2 things:

    1) write a cookie (actually several cookies)
    2) submit the information to a php file

    If the site is coded for one of the commands (either one) the command
    follows the submit. I have tried various ways to recode the form but
    for some reason I can't make both happen on submit; depending on which
    variable is first I either get a nice cookie or php return
    confirmation.

    The goal is to utilize the cookie on a second form to personalize the
    page and to offer verification; I am open to losing the php on the
    first form and sending all the information from both forms to a 3rd
    page verification form with the cookie, but that is a totally
    different problem.

    Any suggestions?

    <form name="freeform" onSubmit="
    if(freeform.fir st_name.value.l ength != 0) {
    var expdate = new Date ();
    expdate.setTime (expdate.getTim e() + (24 * 60 * 60 * 1000));
    SetCookie('Firs tName', freeform.first_ name.value, expdate);
    SetCookie('Last Name', freeform.last_n ame.value, expdate);
    SetCookie('Addr ess', freeform.addres s.value, expdate);
    SetCookie('City ', freeform.city.v alue, expdate);
    SetCookie('Stat e', freeform.state. value, expdate);
    SetCookie('ZipC ode', freeform.zipcod e.value, expdate);
    SetCookie('Birt hMonth', freeform.birthm m.value, expdate);
    SetCookie('Birt hDay', freeform.birthd d.value, expdate);
    SetCookie('Birt hYear', freeform.birthy y.value, expdate);
    SetCookie('Area code', freeform.areaco de.value, expdate);
    SetCookie('Phon ethree', freeform.phonet hree.value, expdate);
    SetCookie('Phon efour', freeform.phonef our.value, expdate);
    SetCookie('Send erEmail', freeform.sender _email.value,
    expdate);
    return false;
    } else {
    alert('Please fill in all the form fields.');
    return false;
    }">
    <form method="post" action="process .php">
    <input type="hidden" name="submit_ch eck" value="1" >


    <!--After Form my submit button:-->

    <input name="submitBut ton" type="image" id="submitButto n" src="images/
    submitbutton.jp g"; />
  • bonus

    #2
    Re: Form Issue - onSubmit canceling Action

    Removing all these cookies is most likely a good idea, but I still
    need the data sent php and nest the cookie data. Right now this
    javascript only sends the cookie and does not process the php file..

    <form name="freeform" method="post" action="process .php" onSubmit="
    if(freeform.fir st_name.value.l ength != 0) {
    var expdate = new Date ();
    expdate.setTime (expdate.getTim e() + (24 * 60 * 60 * 1000));
    SetCookie('Firs tName', freeform.first_ name.value, expdate);
    SetCookie('Send erEmail', freeform.sender _email.value,
    expdate);
    return false;
    } else {
    alert('Please fill in all the form fields.');
    return false;
    }">
    <input type="hidden" name="submit_ch eck" value="1" >

    Thanks.

    On Feb 21, 6:00 pm, Joost Diepenmaat <jo...@zeekat.n lwrote:
    Don't use so many cookies. There's a (fairly small) limit on how many
    cookie data must be stored by a browser.

    Comment

    • Joost Diepenmaat

      #3
      Re: Form Issue - onSubmit canceling Action

      bonus <tb0nus@comcast .netwrites:
      Removing all these cookies is most likely a good idea, but I still
      need the data sent php and nest the cookie data. Right now this
      javascript only sends the cookie and does not process the php file..
      That's because return()ing false from onsubmit prevents the submit. You
      should return true when you want the submit to process.

      --
      Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

      Comment

      • Joost Diepenmaat

        #4
        Re: Form Issue - onSubmit canceling Action

        Joost Diepenmaat <joost@zeekat.n lwrites:
        bonus <tb0nus@comcast .netwrites:
        >
        >Removing all these cookies is most likely a good idea, but I still
        >need the data sent php and nest the cookie data. Right now this
        >javascript only sends the cookie and does not process the php file..
        >
        That's because return()ing false from onsubmit prevents the submit. You
        should return true when you want the submit to process.
        Also, this script does *not* send cookies. It only sets them. Cookies
        are only sent when a request to the server is made and your script does
        not make a request (since it blocks the submit)`.

        --
        Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

        Comment

        Working...