Form Issue - onSubmit canceling Action

B

bonus

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"; />
 
J

Joost Diepenmaat

bonus said:
Any suggestions?

Don't use so many cookies. There's a (fairly small) limit on how many
cookie data must be stored by a browser. Anything over that may be
discarded. Do you really /need/ the visitor's birthmonth and (four!)
phone numbers to be passed to /every single page/?

You're using two nested <form>s. This is unreliable at best. You
probably want to merge the <form> tags.
 
B

bonus

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

Joost Diepenmaat

bonus said:
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.
 
J

Joost Diepenmaat

Joost Diepenmaat said:
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)`.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top