...

View Full Version : Floating Cart Code/Script Problem



dlaw13
12-23-2010, 09:21 PM
Hello All,

So, I have a website with a floating cart and it loads fine and works almost flawlessly lol. However, when a person has a bunch of items in their cart, and they want to minimize it for the rest of their browsing experience, every time a new page loads, or a refresh happens, the floating cart un-minimizes and expands out fully again displaying all the items.

This can become very annoying during the shopping experience when you have a bunch of items loading and just taking up space in the browser. Therefore, I am wondering if their is some html or script that would save the minimizing in the floating cart, and carry it over to the next page, and the rest of the browsing on site?

Thank you for any suggestions/help. I am new to HTML and script writing, but I am eager to learn. Hopefully in the future, I won't be paying for little changes like this every time I need one.

dlaw13
12-23-2010, 09:26 PM
Here is the javascript



<script type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>


And here is the floating cart


<!--Start Floating Cart-->
<div id="dhtmlgoodies_q1" class="dhtmlgoodies_question">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="itemsincart" id="numberofitem" valign="middle" align="left" height="22">Items in your Cart: <span>0</span></td>
<td valign="middle" align="left" style="padding-right:3px;"><a onClick="myshowhide();"><img src="http://site.dlawlesshardware.com/ystore/images/plus-sign-img.jpg" id="showhide" border="0"></a></td>
</tr>
</table>
</div>
<div style="display: none; height: 1px; visibility: visible;" id="dhtmlgoodies_a1" class="dhtmlgoodies_answer">
<div id="dhtmlgoodies_ac1" class="dhtmlgoodies_answer_content">
<table width="176" align="center" border="0" cellpadding="0" cellspacing="0">
</tr>
<tr>
<td align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="rgt-ysc-link" valign="middle" align="left" style="line-height:normal">
<!--Floating Cart Code-->
<table width="150" border="0" cellspacing="0" align="center" cellpadding="0">
</tr>
<tr>

<td align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td id="viewitem" class="view-items" valign="middle" align="center">Your shopping cart is empty.</td>
</tr>

</table>
</td>
</tr>
</table>
<script type="text/javascript" src="http://lib.store.yahoo.net/lib/dlawlesshardware/cookies.js"></script>
<script type="text/javascript" src="http://lib.store.yahoo.net/lib/dlawlesshardware/writeCart.js"></script>
<!--Floating Cart Code-->
</td>
</tr>
</table></td>
</tr>
</table>
</div>
</div>
<table width="153" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="green-bg-txt" valign="top" align="left">Sub Total: <span id="cartitemtotal" class="white-txt">$00.00</span></td>
</tr>
<tr>
<td class="cart-links" valign="top" align="left" bgcolor="#FFFFFF"><a href="http://order.store.yahoo.net/cgi-bin/wg-order?catalog=dlawlesshardware" onclick="pageTracker._link('http://order.store.yahoo.net/cgi-bin/wg-order?catalog=dlawlesshardware',true);"><u>View Cart</u></a> <span>&nbsp;</span> <a href="https://us-dc1-order.store.yahoo.net/dlawlesshardware/ymix/MetaController.html?ysco_key_event_id=1&ysco_key_store_id=dlawlesshardware&sectionId=ysco.ship-bill"><u>Checkout</u></a></td>
</tr>
<tr>
<td valign="top" align="left"><img src="images/spacer.gif" alt="" class="lft-float" width="1" border="0" height="2"></td>
</tr>
<tr>
<td class="rgt-blue-bg-txt" id="shippingmessage" valign="top" align="center"> </td>
</tr>
</table>






<!--End of Start Floating Cart-->

I think part of the problem is I cannot find any mmshowhide function in the javascript. I need to be able to save a cooke and recall it, but I'm in way over my head here. Thanks to anyone who even takes a look, lol.

DJCMBear
12-23-2010, 09:29 PM
Try using a cookie to store a '1' if the cart is open and a '0' if the cart in minimized this way on page load if the functions then check the cookie number if it is set and act accordingly to what number has been set in the cookie.

dlaw13
12-23-2010, 09:44 PM
So I need to create another function in the javascript to create/read this cookie? With an outline similar to this? And how would I sync it up to the showhide shopping cart image button? This might be too much for me to handle...


function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);

DJCMBear
12-23-2010, 09:57 PM
Basicly have an onclick command on what ever the user clicks to minimize the cart and also on the button to un-minimize it, and have this function write to the cookie with 1 or 0 so the button to minimize it would set a 0 and the button to un-minimize it would set a 1.

Then get the current functions that display the cart to read this cookie so if the cookie isn't set or the number inside the cookie equals 0 hide the cart and if the number inside the cookie equals 1 show the cart.

dlaw13
12-23-2010, 10:06 PM
Yeah, this is too much for me. I was hoping I could find some code to copy and paste in the javascript, or beside the cart minimize/maximize button. I need to buy some books on java, scripts, html, etc. and start learning in my free time.

I understand what your saying and the concept behind it, but I can't write that myself. Thank you for the help.

DJCMBear
12-23-2010, 10:10 PM
Yeah, this is too much for me. I was hoping I could find some code to copy and paste in the javascript, or beside the cart minimize/maximize button. I need to buy some books on java, scripts, html, etc. and start learning in my free time.

I understand what your saying and the concept behind it, but I can't write that myself. Thank you for the help.

I will see what I can do to help you out but it will have to been in a bit as I am just doing something right now.

dlaw13
12-23-2010, 10:23 PM
I went ahead and added all of the floating cart code to the original post. I'm not in any hurry, so getting back to me in a couple days or whatever would be awesome.

I appreciate the help, you are going above and beyond in my book.

Thanks :)

DJCMBear
12-23-2010, 11:10 PM
Ignore my PM to you I found your problem... Add this to the header of your site just above the end head tag.


window.onload=initShowHideDivs;

dlaw13
12-24-2010, 04:47 PM
I tried pasting that in the head tags, but it didn't seem to change anything. Let me know if you have anything else up your sleeve.

Thanks

DJCMBear
12-24-2010, 04:53 PM
I had a look at your source code and I don't see it anywhere???

dlaw13
12-24-2010, 05:17 PM
Yes, that's weird, I don't know why its not showing up in the source. My site is a Yahoo Store, so I placed the code in the head tags section under variables. I published and it should have added it. I'm investigating....

dlaw13
12-24-2010, 05:43 PM
<window.onload=initShowHideDivs;> Pasting it like that in another head tags section on y store now....problem is I can't just pull up the code and past it right beside the /head b/c I'm ystore working with rtml and a bunch of boxes that place code for me.

DJCMBear
12-24-2010, 05:46 PM
Paste it just before the closing head tag i.e. </head>.

EDIT: You may have to put this though.



window.onload = (function(){
initShowHideDivs();
fillup();
});

dlaw13
12-24-2010, 05:52 PM
Ok, its not right beside the /head, but you can see it in there now. I'm going to try the new one you just gave me, other one didnt seem to do it.

DJCMBear
12-24-2010, 06:02 PM
I just saw you put the new one in like this.


<window.onload = (function(){
initShowHideDivs();
fillup();
});>


It has to be like this


<script type="text/javascript">
window.onload = (function(){
initShowHideDivs();
fillup();
});
</script>


EDIT: Also you need to remove the old window.onload=fillup; from the page before the onload in the header will work.

dlaw13
12-24-2010, 06:31 PM
wow, you did it! now its setup where it automatically minimizes on every page though, is there a way to set it where if they have it maximized it will stay maximized and if they have it minimized it will stay minimized?

this setup is better than it always defaulting to maximized for sure, thank you so much. if the code for that is a whole other thing don't trouble yourself, you've definitely helped me out enough. thanks again!

DJCMBear
12-24-2010, 06:36 PM
Like in my earlier posts this needs a cookie to be set and updated on min and max of the dropdown but as I haven't looked over the codes on your site I wouldn't know where to edit etc. Maybe look in to javascript cookies and give it a shot yourself, but make a back-up of the original codes before doing anything just in-case it messes up and if there is any problems come back and post a new thread about the problems your having.

dlaw13
12-24-2010, 06:42 PM
Sounds good, have a merry Christmas, and thanks for improving my store. Hey, if you ever need any hardware, I'll give you a 10% discount, just email me lol.

DJCMBear
12-24-2010, 06:52 PM
Sounds good, have a merry Christmas, and thanks for improving my store. Hey, if you ever need any hardware, I'll give you a 10% discount, just email me lol.

Thanks and the same to you, and thanks if I ever need any hardware I'll be sure to contact you. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum