469,322 Members | 1,603 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,322 developers. It's quick & easy.

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.first_name.value.length != 0) {
var expdate = new Date ();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000));
SetCookie('FirstName', freeform.first_name.value, expdate);
SetCookie('LastName', freeform.last_name.value, expdate);
SetCookie('Address', freeform.address.value, expdate);
SetCookie('City', freeform.city.value, expdate);
SetCookie('State', freeform.state.value, expdate);
SetCookie('ZipCode', freeform.zipcode.value, expdate);
SetCookie('BirthMonth', freeform.birthmm.value, expdate);
SetCookie('BirthDay', freeform.birthdd.value, expdate);
SetCookie('BirthYear', freeform.birthyy.value, expdate);
SetCookie('Areacode', freeform.areacode.value, expdate);
SetCookie('Phonethree', freeform.phonethree.value, expdate);
SetCookie('Phonefour', freeform.phonefour.value, expdate);
SetCookie('SenderEmail', 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_check" value="1" >
<!--After Form my submit button:-->

<input name="submitButton" type="image" id="submitButton" src="images/
submitbutton.jpg"; />
Feb 21 '08 #1
3 1440
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.first_name.value.length != 0) {
var expdate = new Date ();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000));
SetCookie('FirstName', freeform.first_name.value, expdate);
SetCookie('SenderEmail', freeform.sender_email.value,
expdate);
return false;
} else {
alert('Please fill in all the form fields.');
return false;
}">
<input type="hidden" name="submit_check" value="1" >

Thanks.

On Feb 21, 6:00*pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
Don't use so many cookies. There's a (fairly small) limit on how many
cookie data must be stored by a browser.
Feb 22 '08 #2
bonus <tb****@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/
Feb 22 '08 #3
Joost Diepenmaat <jo***@zeekat.nlwrites:
bonus <tb****@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/
Feb 22 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by greg brant | last post: by
2 posts views Thread by JHB | last post: by
3 posts views Thread by eric.goforth | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.