Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About mac007

  • Rank
    Advanced Member

Profile Information

  • Gender
    Not Telling
  1. Ahh.. I see it's a bit different - gonna try that out tomorrow, Thanks again!
  2. Thanks requinix, I took a look at it and looks like it's what I need... I found this script that uses that - I tried to get the variable to show up, but somehow havent been able to do it - this is what I have, assuming the URL has a "post=xyz" parameter in it. I'm very green with JS, so havent been able to figure out what I'm missing, Thanks for your help! <script> function getUrlParameter(name) { name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec(location.search); return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); }; </script> <p id="demo"></p> <script> document.getElementById("demo").innerHTML.getUrlParameter('post'); </script>
  3. Hi, I need a JAVASCRIPT snippet that can "read" a specific url parameter going to a cart, and embeds it into a link and if parameter is not present then use a default value, so say something like this... This would be url-link: www.shoppingcart.com?source-code=XYZ&date=whatever&name=whatever So, when one arrives at that page, there is a buy-link, and I need javascript to embed the "source-code" url-parameter into the link like this: <a href="http://www.shoppingcart.com?add-item=shoes&source-code=XYZ"> Buy! </a> So, as you see, the "source-code" parameter gets automatically inserted into the buy-link, I've done this sort of stuff rather easily thru PHP like this: https://shoppingcart.com?add-item=shoes&source-code=<?php if(isset($_GET['source-code'])) {echo $_GET['source-code'];} else { echo "DEFAULTCODEā€¯;} ?> But I havent been able to get it working just right in javascript, does anyone have any ideas best way to accomplish this? Appreciate any help! :)
  4. Thank you much bsmither for taking the time to reply. I will try that! I think lots of us here are not full-fledged php experts as Guru [Jacques1] would like us all to be, else we (I) wouldnt be here. This is a great forum and place to learn, and figure out stuff as we try out our skills. At any rate, I very much appreciate your feedback without having to resort to rather nasty, condescending attitude in the process... Thank you!
  5. Hi all, I adapted this simple shopping cart into my site, but it's got 2 issues... 1) if a product is already in the cart, and I add another quantity to it, it doesnt add the quantity to the same product, it simply adds it as another item in the cart and... 2) if I click on "Remove item" from the cart, it only removes the item if there's only one item in it, if there are many items, it then doesnt do anything. Appreciate any help!! Tnanks! Here's the code: /* THIS FIRST SECTION IS THE MAIN CART SCRIPT */ require_once("Connections/dbcontroller.php"); $db_handle = new DBController(); if(!empty($_GET["action"])) { switch($_GET["action"]) { case "add": if(!empty($_POST["quantity"])) { $productByCode = $db_handle->runQuery("SELECT * FROM works WHERE ProductID='" . $_GET["code"] . "'"); $itemArray = array($productByCode[0]["ProductID"]=>array('name'=>$productByCode[0]["Description"], 'code'=>$productByCode[0]["ProductID"], 'quantity'=>$_POST["quantity"], 'price'=>$productByCode[0]["Price"])); if(!empty($_SESSION["cart_item"])) { if(in_array($productByCode[0]["ProductID"],$_SESSION["cart_item"])) { foreach($_SESSION["cart_item"] as $k => $v) { if($productByCode[0]["ProductID"] == $k) $_SESSION["cart_item"][$k]["quantity"] = $_POST["quantity"]; } } else { $_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray); } } else { $_SESSION["cart_item"] = $itemArray; } } break; case "remove": if(!empty($_SESSION["cart_item"])) { foreach($_SESSION["cart_item"] as $k => $v) { if($_GET["code"] == $k) unset($_SESSION["cart_item"][$k]); if(empty($_SESSION["cart_item"])) unset($_SESSION["cart_item"]); } } break; case "empty": unset($_SESSION["cart_item"]); break; } } /* AND THIS SECTION HERE IS THE CART-DISPLAY HTML SECTION*/ <div id="shopping-cart" align="center"> <div class="txt-heading">Shopping Cart <a id="btnEmpty" href="shopping-cart.php?action=empty">Empty Cart</a><br /> <br /> </div> <?php if(isset($_SESSION["cart_item"])){ $item_total = 0; } ?> <table width="600" border="1" align="center" cellpadding="5" cellspacing="0"> <tr> <td><strong>Name</strong></td> <td><strong>Code</strong></td> <td><strong>Quantity</strong></td> <td><strong>Price</strong></td> <td><strong>Action</strong></td> </tr> <?php foreach ($_SESSION["cart_item"] as $item){ ?> <tr> <td><strong><?php echo $item["name"]; ?></strong></td> <td><?php echo $item["code"]; ?></td> <td><?php echo $item["quantity"]; ?></td> <td align=right><?php echo "$".$item["price"]; ?></td> <td><a href="shopping-cart.php?action=remove&code=<?php echo $item["code"]; ?>" class="btnRemoveAction">Remove Item</a></td> </tr> <?php $item_total += ($item["price"]*$item["quantity"]); } ?> <tr> <td colspan="5" align=right><strong>Total:</strong> <?php echo "$".$item_total; ?></td> </tr> </table> </div>
  6. Wow, you are AWESOME Mac_giver! It worked like a charm! Thanks a lot for your help... I'm more of web-designer who dabbles here and there with PHP and javascript when needed... so my knowledge on it is very limited as much of my time is spent so much on design aspect. Again, thanks a lot!
  7. Hi all, I have this JQUERY/JAVASCRIPT SNIPPET right now that will check if an item has a quantity selected out of a long list of product select-menus - it works fine, EXCEPT, I want it to work so it allows it to submit even if the item they may have clicked was NOT the one that had the quantity selected. In other words, not have the submit button tied to the specific item its on, but to the fact that there has been an item somewhere in the form that has a quantity selected. Right now, the way it is, person has to click any of the items that have a quantity selected. The problem is if a person goes all the way down a long list of products, I want them to simply click on any submit button from whereever they are, and not have to climb back up the page to click on the submit button of any of the products they did chose a quantity for... This is the code here: $(document).ready( function() { $('input[type="image"]').click( function() { var quantity = new Array; quantity[1] = $(this).closest('tr').find('select').val(); if(quantity[1] == 0) { alert("You have not selected a product quantity!"); return false; } }); }); THIS IS THE BASIC HTML FOR ONE OF THE PRODUCTS... ITS A LONG LIST OF LIKE 50 PRODUCTS, ONE AFTER THE OTHER... PRODUCT A (SAY I SELECT QUANTITY ONE HERE ON THIS PRODUCT) <----------------- <td width="10%" align="center" valign="middle" >Qty: <select class="qty" name="qty189" id="qty_189" > <option value="0">0</option> <option value="1">1</option> </select> <br /> <input type="hidden" name="action" value="AddCart" /> <input type="hidden" name="process_type" value="2" /> <br /> <input name="submit" type="image" value="Add To Cart" src="offer-button.gif" /> </td> NEXT PRODUCT B NEXT PRODUCT C NEXT PRODUCT D NEXT PRODUCT E (BUT PERSON CLICKS ON THIS SUBMIT BUTTON - ALLOW IT SINCE THERE'S A QUANTITY SELECTED FOR PRODUCT A) <----------------- ETC, ETC... Appreciate any help... Thanks!
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.