Forum Moderators: open
Why two forms? Well, one button adds a product to a shopping cart which is then sent to Paypal or other options for checkout. Paypal description and option fields are limited so I must receive additional form data by email (in addition to the Paypal order).
Basically, I need an if then statement on my add to cart button. I'm sure this is simple for you JS experts. First, ordform is validated. If not complete, do not add the item to the cart. If complete, add the item to cart and send me an email containing the inputs of the ordform.
Here's my code:
..snip..
<!--
function Verify()
{
if (document.ordform.name.value=="")
{
alert("Please enter your name.");document.ordform.name.focus();return false
}
if (document.ordform.address1.value=="")
{
alert("Please enter Address Line 1.");document.ordform.address1.focus();return false
}
if (document.ordform.city.value=="")
{
alert("Please enter your city.");document.ordform.city.focus();return false
}
if (document.ordform.state.value=="")
{
alert("Please enter your state.");document.ordform.state.focus();return false
}
if (document.ordform.zip.value=="")
{
alert("Please enter your zip code.");document.ordform.zip.focus();return false
}
}
//-->
</script>
..snip..
<form name="ordform" method="post"
action="/cgi-bin/myscript.cgi" target="_blank">
<input type="text" name="name" size="50" />
<input type="text" name="address1" size="50" />
<input type="text" name="address2" size="50" />
<input type="text" name="city" size="50" />
<input type="text" name="state" size="10" />
<input type="text" name="zip" size="10" />
</form>
..snip..
<form action="javascript: void (0);" method="post" >
..snip..
<input name="button" type="button"
value="Add To Cart"
onclick="document.ordform.submit();" />
I know its simple, just don't know JS too well.
Thanks much!
Dan
The javascript part of the problem is not to difficult, but you do need to figure out what you are going to do with the web pages you receive back. Each form will send back a webpage, so that lands you in trouble, unless one of the forms is received by a pop-up you launch.
You'd need a second form with the additional info you require, plus a number of hidden form elements. The hidden elements would need to match the visible ones on the form for paypal. Then in your onclick, you copy the contents of each of the 'paypal' form elements to the respective hidden form element, then submit each form.
Hope that makes sense.
(BTW, how are you finding Paypal?; they seem to be under a lot of scrutiy and class actions for defrauding merchants and freezing their accounts with no explanation.)
Shawn
He changed my JS to this:
<script type="text/javascript">
<!--
function Verify(obj) {
if (obj.name.value=="") {
alert ("Please input your name!");
return false;
}
if (obj.address1.value=="") {
alert ("Please input Address 1!");
return false;
}
if (obj.city.value=="") {
alert ("Please input your City!");
return false;
}
if (obj.state.value=="") {
alert ("Please input your State!");
return false;
}
if (obj.zip.value=="") {
alert ("Please input your Zip Code!");
return false;
}
return true;
}
//-->
</script>
THEN FOR MY ADD TO CART BUTTON, I JUST NEEDED THIS...
<input type="button" value="Add To Cart"
onclick="if (Verify (document.forms.ordform)) { document.ordform.submit();
ReadForm (this.form);
CallView ();
}" />
ReadForm is a function that processes my second form. CallView is a function that invokes the viewing of the shopping cart contents. There are some other calls in the event handler of the onclick function that are specific to the script that I left out, but this works.
Korkus, in regards to question on server side scripting, my web host is linux based so I have access to PHP. But this is a client side shopping cart written in JS. This meets my needs for now. For another site I'm working on, I would like to setup dynamically generated pages using a mysql db and PHP, along with a cart that interfaces with Paypal. I've seen free carts out there that do this, but they are not that great. You get what you pay for as they say. If anyone knows of any good free ones out there, let me know.
Shawn, thanks for the welcome! This is a great forum. I understand your idea, but now that I got it working, I don't want to break it : )
In regards to Paypal, I did not hear about the issues you mentioned. I haven't been defrauded and my account has never been frozen, not yet anyway. I love Paypal. It's an easy way to accept payment for just about anything in a secure fashion. I don't like the fact of storing credit card info on a server hosted by someone I've never met. I'll let paypal handle that liability. Millions of people have Paypal accounts. You can accept various currencies, allowing global ecommerce. In addition, sending money by email seems to create impulse buying. Your customers don't have to fill out long forms with their name, billing address, shipping address, etc. every time they buy something. Just log in and pay. I can handle the fees - they are only 1% higher than my regular offline merchant account. The pros seem to outweigh the cons IMO.
I'm sure this topic could spark an entire new thread : )
Dan
The pros seem to outweigh the cons IMO.
I'm sure this topic could spark an entire new thread : )
OK, good to hear. Maybe they've smartened up their act, or maybe you've been lucky. If you want to see what I am talking about, just google for 'paypal'. On the first screenful you should one official paypal site, and 4 or 5 independant sites warning of the dangers. Seems people have been refering complaints about paypal to the FBI as recently as 16 April 2003.
I didn't want to veer the thread of topic. I was just curious. Good to hear you are having a good experience.
Shawn