Jump to content

Flic

Members
  • Posts

    22
  • Joined

  • Last visited

Flic's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Hi, I made a page with two drop boxes in, with the aim of repeating a lot of times. I set it up so that instead of repeating the options for each box they would be filled in when the page was loaded. The two boxes worked fine with that and a number of other functions they performed but now I've come to duplicate them and I've hit a problem. I have named each drop down box consecutively (sp?) and have a while loop to fill them but its not working. Please see the code below: function load(){ var i = 0; while (i <= 10) { var selcat = ("category" + i); var selpri = ("price" + i); var selnam = ("name" + i); document.order.selpri.value = ""; document.order.selcat[0] = new Option("Please select...", "cat", true); document.order.selcat[1] = new Option("Accessories", "acc", false); document.order.selcat[2] = new Option("Bolted Silo", "bol", false); document.order.selcat[3] = new Option("Welded Silo", "wel", false); document.order.selcat[4] = new Option("Horizontal Silo", "hor", false); document.order.selnam[0] = new Option("Please select a category...", "cat", false); i++; } } Am I being really silly and missing something obvious? I tried using getElementById but that didn't work, I'm thinking because technically its not the id. Any help would be much appreciated! Thanks
  2. Hi, I have some shopping basket code which works in that the item gets added to the shopping basket, but the information (name, price etc) isn't carried over.I've only recently started learning php so am not sure why it doesn't work properly and would really appreciate it if someone could take a look and let me know where I am going wrong. It did work before but I heavily modified it for my needs hence it not working now Code that its being called from: <?php$products = array();$products[1] = array("id"=>123,"name"=>"Silo Venting Filter","price"=>123.45,"sub"=>"venting_system", "desc"=>"A cylindrically shaped dust collector for venting of pneumatically filled silos, the stainless steel body contains vertically mounted filter elements. The air jet cleaning system is integrated in the hinged weather protection cover.");foreach($products as $p) {echo "<div class='acc'>";echo "<form method='post' action='cart.php'>";echo "<input type='hidden' name='id' value='".$p['id']."'/>";echo "<img src='images/".$p['sub'].".jpg' alt='".$p['name']."'>";echo "<div><h1><a class='silolink' href='accessories/".$p['sub'].".html'>".$p['name']."</a></h1>";echo $p['desc'];echo "<br><br>£".$p['price'];echo "<input type='submit' value='Add to cart' name='add'></form>";echo "</div></div>";}?> The cart page: <?phpsession_start();$cart =& $_SESSION['cart']; // point $cart to session cart.if(!is_object($cart)) $cart = new siloCart(); // if $cart ( $_SESSION['cart'] ) isn't an object, make a new cartclass siloCart { var $total = 0; var $itemcount = 0; var $items = array(); var $itemprices = array(); var $itemqtys = array(); var $iteminfo = array(); function cart() {} // constructor function function get_contents() { // gets cart contents $items = array(); foreach($this->items as $tmp_item) { $item = FALSE; $item['id'] = $tmp_item; $item['name'] = $this->itemname[$tmp_item]; $item['price'] = $this->itemprices[$tmp_item]; $item['sub'] = $this->itemsub[$tmp_item]; $item['desc'] = $this->itemdesc[$tmp_item]; $item['subtotal'] = $item['qty'] * $item['price']; $items[] = $item; } return $items; } // end of get_contents function add_item($itemid,$qty=1,$price = FALSE, $info = FALSE) { // adds an item to cart if($this->items[$itemid] > 0) { // the item is already in the cart.. // so we'll just increase the quantity $this->itemqtys[$itemid] = $qty + $this->itemqtys[$itemid]; $this->_update_total(); } else { $this->items[]=$itemid; $this->itemqtys[$itemid] = $qty; $this->itemprices[$itemid] = $price; $this->iteminfo[$itemid] = $info; } $this->_update_total(); } // end of add_item function edit_item($itemid,$qty) { // changes an items quantity if($qty < 1) { $this->del_item($itemid); } else { $this->itemqtys[$itemid] = $qty; } $this->_update_total(); } // end of edit_item function del_item($itemid) { // removes an item from cart $ti = array(); $this->itemqtys[$itemid] = 0; foreach($this->items as $item) { if($item != $itemid) { $ti[] = $item; } } $this->items = $ti; $this->_update_total(); } //end of del_item function empty_cart() { // empties / resets the cart $this->total = 0; $this->itemcount = 0; $this->items = array(); $this->itemprices = array(); $this->itemqtys = array(); $this->itemdescs = array(); } // end of empty cart function _update_total() { // internal function to update the total in the cart $this->itemcount = 0; $this->total = 0; if(sizeof($this->items > 0)) { foreach($this->items as $item) { $this->total = $this->total + ($this->itemprices[$item] * $this->itemqtys[$item]); $this->itemcount++; } } } // end of update_total}?><html here><?phpif($_POST['add']) { $product = $products[$_POST['id']]; $cart->add_item($product['id'],$product['price'],$product['name']);}if($_POST['remove']) { $rid = intval($_POST['id']); $cart->del_item($rid);} echo "<table><tr><td>ID</td>"; echo "<td>Name</td>"; echo "<td>Price</td>"; echo "<td>Quan</td>"; echo "<td>Subtotal</td></tr>";if($cart->itemcount > 0) { foreach($cart->get_contents() as $item) { echo "<tr><td>".$item['id']."</td>"; echo "<td>".$item['info']."</td>"; echo "<td>".number_format($item['price'],2)."</td>"; echo "<td>".$item['qty']."</td>"; echo "<td>".number_format($item['subtotal'],2)."</td>"; echo "<td><form method=post><input type='hidden' name='id' value='".$item['id']."'/><input type='submit' name='remove' value='X'/></form></td></tr>"; } echo "<tr><td colspan=4>Sub total:</td><td>£".number_format($cart->total,2)."</td></tr>"; echo "<tr><td colspan=4>VAT:</td><td>£".number_format($cart->total,2)."</td></tr>"; echo "<tr><td colspan=4>Total:</td><td>£".number_format($cart->total,2)."</td></tr>"; echo "</table>"; } else { echo "<tr><td colspan=5>- No items found in cart -</td></tr>"; echo "</table>";}?></div></div></body></html> Any help would be much appreciated!Thanks!
  3. Hi,I'm using floats to make some images I have lie in line with the text. This was the only way I could think of to do this but it means that the next pic starts when the paragraphy next to the pic stops, not ideal. The code I have currently is: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><link rel="stylesheet" type="text/css" href="---.css"><style type="text/css">img {float: left;border-right-style: solid; border-right-color: white; border-right-width: 10px;border-bottom-style: solid; border-bottom-color: white; border-bottom-width: 10px;}h1 {font-size: 120%;font-weight: bold;}</style></head><body><div id="logo"></div><div id="header"><div id="linkcontainer"><a href="index.html" class="links">About</a><a href="products.html" class="links">Products</a><a href="prices.html" class="links">Prices</a><a href="accessories.html" class="links" style="width: 17%;">Accessories</a><a href="contact.html" class="links">Contact</a><a href="cart.php" class="links">Cart</a></div></div><div id="content"><p><img src="silo_small.jpg" alt="Click for a bigger photo"><h1>Silo name</h1>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent hendrerit dolor sit amet enim. Nunc elementum ligula quis dui. Curabitur convallis velit a tortor. Phasellus at dui. Aenean at tortor ut lorem rutrum facilisis. Cras sed sem eu tellus malesuada pulvinar. Nullam posuere, magna nec pretium euismod, eros turpis luctus lectus, ac semper diam justo nec felis. Phasellus lobortis, erat id sagittis aliquam, dolor mauris aliquam neque, ac dapibus massa felis in est. Ut auctor orci vel nulla. Integer vitae orci. Sed rutrum euismod nulla. Donec sapien.</p><br><p><img src="silo_small.jpg" alt="Click for a bigger photo"><h1>Silo name</h1>Aliquam vitae pede. Aenean semper eros eget leo. Fusce sed dolor. Integer id arcu sed libero eleifend bibendum. Phasellus accumsan arcu quis est. In pellentesque augue auctor lorem. Pellentesque condimentum vehicula eros. Suspendisse sed risus quis sapien dapibus tincidunt. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris convallis viverra tortor. ###### sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nunc magna lacus, pharetra non, rutrum ac, nonummy a, elit. Proin dictum. Donec consequat gravida lectus. Sed arcu. Aliquam pulvinar euismod ipsum. Nulla lorem dolor, ullamcorper a, ultrices non, venenatis sed, enim. Donec congue odio vel nibh. Integer ac orci.</p><br><p><img src="silo_small.jpg" alt="Click for a bigger photo"><h1>Silo name</h1>Proin dapibus gravida mauris. Curabitur dignissim mauris ac lacus. Nunc vel nunc non magna rutrum congue. Aliquam leo. Vivamus ac sapien. Nulla facilisi. Proin sit amet nibh. Sed elit dolor, ultrices nec, suscipit vitae, rutrum non, pede. Cras posuere venenatis mi. Pellentesque pretium accumsan ligula. Pellentesque facilisis, lectus in faucibus laoreet, enim sapien iaculis tellus, pulvinar cursus turpis elit ac risus. Aliquam erat volutpat. Etiam rutrum eros at sapien. Pellentesque quis lacus.</p><br></div></body></html> The photos should be in line with each other with the text to the right.Any hints to fix it or an alternative method would be much appreciated.Thanks!Flic
  4. Ok, just to let you know I've finally got it working perfectly!Apparently it worked as long as there was nothing in enquiry. If there was it would overwrite all the falses generated before.I've reworked the logic a bit and it did the trick!Yay
  5. The validation always worked, it would come up with the errors but then continue to send it, which obviously I don't want. I've now got it backed up with PHP validating as I'm using PHP to send it anyway.However I would still like the javascript stopping it if the entries don't validate. I can't see anything which should mean its sending when it shouldn't be.
  6. Eep, arguing on my thread!And its still not stopping it *Goes off to look at PHP validation*
  7. Hi,www.gecofabrications.co.uk/contact.html is as you can see a contact form. This is validated using javascript and that works ok, however even when the form validation fails the form still gets sent!Anyone know why?Any help much appreciated!Flic
  8. Flic

    Bottom positioning

    Hi,I'm trying to position something on the bottom right corner of my page using CSS. I'm using the following code to do that but it hasn't come out how I wanted. #bottom {position: absolute;bottom: 0px; right: 0px;width: 500px; height: 30px;background-color: #D5DCFF;border-style: solid; border-width: 1px; border-color: #000000;} It does position it on the bottom right perfectly, until the content runs longer than the page, the div doesn't move to accommodate it. I've tried relative positioning but that was worse.Any pointers to make this work would be much appreciated!Thank you
  9. Flic

    no properties

    Thats right. The style should affect a form that I have on the same page. Any idea how to fix it? I'm out of ideas right now!
  10. Flic

    no properties

    This is probably going to be one of those silly little things, but if it is could someone point it out as for the life of me I can't see it!I have the following code, part of it works part of it doesn't: function changeColour() {var selection = (document.select.colour.selectedIndex);var picture = ((document.select.colour.options[selection].value) + ".jpg");var text = ((document.select.colour.options[selection].value) + "Text");document.colour.src = picture;document.text.style.display = "";} The picture section of it works fine, however the style bit doesn't, I get "document.text has no properties", I know what it is telling me but I don't know why it is telling me that.The code works if I substitute in the name but obviously I don't want to do that!Any help appreciated!
  11. I have found before that images wouldn't show because the compression for the jpg was only at 1, might not be it but then might be something to check.
  12. Thank you Scott! I normally check things like closing brackets by doing replace all on them, but I was too tired and just did it visually and of course I didn't see the one at the end of the line as it was off screen!To clarify, by calling the form in the method I can call them all the same thing and it will still work?
  13. Ok, this should be simple enough but IE says there is a problem with it on the select statement line of the form and I can't see anything wrong which is rather annoying. This is almost working fully now with one item and I'll expand it when its working fully. The jist of what I am trying to do is to bring up an alert box if a particular option is chosen, I will add to this so that it only happens once per page, one step at a time! <html><head><script type="text/javascript">function open_win(){window.open("../colours/colours.html", "Colours", 'width=300, height=350')}function colourCheck(){var selection = document.add.os0.selectedIndex;if (selection == 5) {alert("You have specified other colours, please check the colour chart and specify colours at checkout. Thank you.")}}}</script></head><body><table width=100% border=0><tr><td width=250><img src="../necklaces/blueFlower.jpg" alt=Blue Flower necklace></td><td>Description will go here</td><td width=200 align=center><p><a href="javascript:open_win()">Colour combinations</a></p><p><b>£9.99</b></p><form name="add" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"><p><input type="hidden" name="on0" value="Colour"><select name="os0" onchange="colourCheck()"><option value="Jet and Black Diamond">Black / Grey</option><option value="Capri and Aquamarine">Blue / Light Blue</option><option value="Amethyst and Light Amethyst">Purple / Light Purple</option><option value="Light Siam and FireOpal">Red / Orange</option><option value="Garnet and Light Rose">Dark Red / Pink</option><option value="Other colours (please specify)">Other colours</option></select></p><p><input type="hidden" name="add" value="1"><input type="hidden" name="cmd" value="_cart"><input type="hidden" name="business" value="email"><input type="hidden" name="item_name" value="Two strand flower necklace"><input type="hidden" name="amount" value="9.99"><input type="hidden" name="no_shipping" value="2"><input type="hidden" name="currency_code" value="GBP"><input type="hidden" name="lc" value="GB"><input type="hidden" name="bn" value="PP-ShopCartBF"><input type=submit value="Add to basket"></p></td></tr></form></body></html> Also a quick note, if I have multiple forms on a page can I call them the same thing? It'll be performing the same function and it'll save me duplicating methods for the different forms.Thank you!
  14. Apparently because i did the picture so quickly, it was just a square of the relevant colour, the compression of the jpg made it mess up, it was on 1 and now its on 10 its working fine.I thought i was going crazy! I couldn't even get a simple link to the picture to work!All sane again now! Thank you!
×
×
  • Create New...