Page 1 of 1
Shopping cart function, need help...
Posted: Mon Oct 31, 2005 3:09 pm
by WithHisStripes
Heya,
I need to create a way that a user can click a checkbox (that's in a seperate JS window) and click an "add to cart" button where it is then sent to a temporary shopping cart. Can anyone help?
Thanks!
-Spence
Posted: Mon Oct 31, 2005 3:14 pm
by Burrito
That's a very vague question.
But, from what I gather you want to be able have a separate window/frame where a user can select a product that would then add an item to a shopping cart (I assume the cart is "housed" on the parent window/frame).
if that's the case, you'll need JS to do it:
something like:
this assumes a separate "pop-up" window
Code: Select all
<script>
updateParent(what)
{
if(what.checked)
opener.document.someForm.item.value = what.value
}
</script>
<input type="checkbox" name="someProduct" value="myProduct" onClick="updateParent(this)">
Posted: Mon Oct 31, 2005 3:22 pm
by WithHisStripes
Yeah, that's exactly what I'm trying to accomplish.
Thanks, that code brings me a little closer. Now, that's just the code for my checkbox and the code to update my parent directory once they hit the submit button, but I don't have a parent directory either. Can you help me figure out how to create that parent directory? I'm not using a user login or any of that, simply their order needs to be cached until they leave the site.
I am building this thing from scratch and I'm not experienced, so bear with me. Thanks a ton
-Spence
Posted: Mon Oct 31, 2005 4:35 pm
by Burrito
the best way to do it would be to set up sessions (not to log in, but to "capture" and "hold" the cart info). So if you used my example above, you could update the form field on the parent page then submit the form to add the item to the cart. Using that method will allow you to add something to a session variable as well (perhaps the cart ID from a DB or the like) and then rebuild the page from the server side.
the alternative (and the way that I *personally* would do it) would be to use DHTML to modify the parent page and reflect the updated cart information on the client side. They could then click the shopping cart to see details about info in the cart, or proceed to a checkout... etc etc.
Posted: Mon Oct 31, 2005 5:08 pm
by WithHisStripes
Okay, yeah that's what some other people suggested, using sessions. Now, I understand how it works, but I don't know where to begin, and I'm not experienced with PHP enough to write my own code that is that complex, are there some resources that you could point me to that could help me build it as simply as possible? Do you have a script I could use maybe? Thanks so much bud!
-Spence
Posted: Mon Oct 31, 2005 5:54 pm
by Burrito
check out hotscripts.com. I'm certain they'll have a shopping cart there.