javascript and image display help needed

They have: 14 posts

Joined: Jun 2000

Hi!

I sure hope I will find a bit of help here, i have been trying to get this going for a few months now, here is the problem... i have a javascript cart and when you select the items it stores the product name in the cookie, when you view the cart content instead of having the product name displayed i need the product image displayed, here is a copy of the product page javascript, this cart is in 2 parts, product pages and the index, if you need to see the index please email me, i will send it, the item name here is image1, this is what is displayed in the view cart content, instead i need the image.

thanks !

<script>
// Dreamweaver Object created by Andrew Wooldridge [email protected]
theStuff=""
function startUp(){
theStuff=""
theStuff+="<script>\r"
theStuff+=" function stopErrors(){ \r"
theStuff+=" return true;"
theStuff+="} \r"
theStuff+="window.onerror=stopErrors\r"
theStuff+="</scr"
theStuff+="ipt>\r"

}

function objectTag(){
startUp()
return theStuff

}

</script>
<script language="javascript">
<!-- hide

function write_to_field(code)
{
var found = false;
var i =0;
while ((found == false) && (i < document.form1.elements.length))
{i = i + 1
if (document.form1.elements[i].name == code)
{
found = true;
document.form1.elements[i].value = parent.item_quan(code);
}
}
}

function Loc_additem(code,price,desc,url)
{
self.parent.additem(code,price,desc,url);
write_to_field(code)
}

function Loc_subitem(code,price,desc,url)
{
self.parent.subitem(code,price,desc,url);
write_to_field(code)
}

function update_thiselem_page()
{
if (self!=parent)
parent.update_this_page()
}

<!-- End -->
</script>
<script language="JavaScript">

function tmt_backtoframe(myframe) {
if (top == self) {
self.location.href = myframe;
}
}

</script>
</head>

<body bgcolor="#FFFFFF" alink="#FF0000" onLoad="update_thiselem_page()" link="#0000CC"
vlink="#0000CC" text="#2A2A2A">

<p> </p>

<form name="form1">
<div align="center"><center><p><font face="Verdana, Arial, Helvetica, sans-serif" size="5">Page
One </font></p>
</center></div><div align="CENTER"><table cellspacing="20" width="605">
<tr>
<td colspan="2"><table border="0" width="100%" cellspacing="10">
<tr>
<td width="67%" height="238"><img src="http://www.couponpalace.com/logo.jpg" width="302" height="403"></td>
<td width="33%" height="238"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">The
image displayed could be a set of thumbnails, that when clicked will open another page or
new customised window - enabling the visitor to stay in your store. When browsing is
finished, the visitor can close the display window and return here for continued surfing
of your catalogue.</font></td>
</tr>
</table>
<div align="left"><p><font face="Verdana, Arial, Helvetica, sans-serif" color="#FFFFFF"
size="3"><b><b><img src="ltgreyline.gif" width="560" height="1"></b></b></font></p>
</div><div align="left"><p><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Product</b></font></p>
</div><div align="left"><p><font face="Verdana, Arial, Helvetica, sans-serif" size="2">There
is only one product on this page which can be used as the master template for all your
catalogue pages if only one product is required per page... for example, if you are
presenting images of artworks or similar that the visitor needs to see as large as
possible.</font></td>
</tr>
<tr>
<td width="246"><div align="left"><p><!-- Below are the shopping cart order items --><font face="Verdana, Arial, Helvetica, sans-serif"
size="2">Price $10.00 </font></td>
<td width="402"><input name="addbox" type="button" value="Add this item"
onClick="Loc_additem('page1i1','10','image1','pageone.html')"> <input type="button"
name="subbox" value="Clear item"
onClick="Loc_subitem('page1i1','10','Product_Name','pageone.html')"> <font color="#FFFFFF"> 
</font><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Ordered:</font> <input
type="text" name="page1i1" size="2"> </td>
</tr>
</table>
<font face="Verdana, Arial, Helvetica, sans-serif" color="#FFFFFF" size="3"><b><b>
<dd><img src="ltgreyline.gif" width="560" height="1"></b></b></font> </dd>
</div><div align="center"><div align="center"><center><p><!-- Below are the links back to other pages pages --> </p>
</center></div><div align="center"><center><p><font
face="Verdana, Arial, Helvetica, sans-serif" size="1"><a
href="javascript arent.updatemain_order()"><img src="pics/vieworder.jpg" width="110"
height="18" border="0"></a></font> </p>
</center></div></div>
</form>
</body>
</html>

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi,

Maybe I'm going blind, but I see no code for the cookie, nor any reference for 'code' other than in write_to_field() function.
How are you maintaining your images? In an array? Are they hooked to the product names? or a product id? Why not add the image srcURL to the cookie? You will need to save space for the image, or put up a different page entirely.
If you have an array set up as follows:
var products = new Array();
products[0] = productID;
products[1] = productName;
products[2] = imageSrc;
....
you can access the image with:

for (i = 0; i < products.length; i+3)
{
if (product[i] == productName)
{
imageSrc = products[i+2]
break;
}
}
Then you need to load the image:

image.src = imageSrc;

Hope this helps
Vinny

------------------
my site:GrassBlade: cut&paste javascript
moderator at:The Javascript Place
Javascript City

Where the world once stood
the blades of grass cut me still

They have: 5,633 posts

Joined: Jan 1970

hi

your right, the actual cookie code is in the other file, this is basically a cart script.. a very simple one, the following is the index.html file, above was the product template page, no admin features.. nothing, simple and straight to the point, i just want the images to show up and to i will take out what I dont need after (prices, qty, s/h, etc etc )

hope you can guide me a litle bit !

thanks !

begin code
***************************
<script>
theStuff=""
function startUp(){
theStuff=""
theStuff+="<script>\r"
theStuff+=" function stopErrors(){ \r"
theStuff+=" return true;"
theStuff+="} \r"
theStuff+="window.onerror=stopErrors\r"
theStuff+="</scr"
theStuff+="ipt>\r"

}

function objectTag(){
startUp()
return theStuff

}

</script>
<script language="javascript">

<!-- hide
order_total =0;
item_num = 1
present_item = 1;
items_ordered = 0;
total_item_price =0;
maxarray = 50
var st_astr = '<html><body bgcolor=#ffffff>'
var en_astr = '</body></html>'
grand_total_again = 0;

function getCookie (name) {
var dcookie = document.cookie;
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
while (cbegin < clen) {
var vbegin = cbegin + cname.length;
if (dcookie.substring(cbegin, vbegin) == cname) {
var vend = dcookie.indexOf (";", vbegin);
if (vend == -1) vend = clen;
return unescape(dcookie.substring(vbegin, vend));
}
cbegin = dcookie.indexOf(" ", cbegin) + 1;
if (cbegin == 0) break;
}
return null;
}

function setCookie (name, value, expires) {
if (!expires) expires = new Date();
document.cookie = name + "=" + escape (value) +
"; expires=" + expires.toGMTString() + "; path=/";
}

function delCookie (name) {
var expireNow = new Date();
document.cookie = name + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
}

var shiparray = new parent.createArray(10);

function getCookieArray(name){
var i = 0;
while (getCookie(name + i) != null) {
shiparray[i + 1] = getCookie(name + i);
i++;
shiparray.length = i;
}
}

var expdate = new Date();

expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365));

function setCookieArray(name){
temp_length = setCookieArray.arguments.length - 1;
for (var i = 0; i < temp_length; i++) {
data = setCookieArray.arguments[i + 1]
setCookie (name + i, data, expdate);
}
}

function go_with_cookie()
{
setCookieArray('gifttails',
parent.ship_details.f_namea,
parent.ship_details.l_namea,
parent.ship_details.email,
parent.ship_details.ad_onea,
parent.ship_details.ad_twoa,
parent.ship_details.citya,
parent.ship_details.statea,
parent.ship_details.countrya,
parent.ship_details.zipa);
}

function get_that_cookie()
{
var i;
getCookieArray('gifttails');
//alert('shiparray.length = '+ shiparray.length);
for (i=0;i<shiparray.length+1;i++)
{if (shiparray[i])
{ //alert('ship_array[' + i + '] ='+ shiparray[i]);
ship_details[i] = shiparray[i];
//alert('ship_details[' + i + '] ='+ ship_details[i]);
}
else
{// to initiate array values
ship_details[i] = ''
}
}

parent.ship_details.f_namea = ship_details[1];
parent.ship_details.l_namea = ship_details[2];
parent.ship_details.email = ship_details[3];
parent.ship_details.ad_onea = ship_details[4];
parent.ship_details.ad_twoa = ship_details[5];
parent.ship_details.citya = ship_details[6];
parent.ship_details.statea = ship_details[7];
parent.ship_details.countrya = ship_details[8];
parent.ship_details.zipa = ship_details[9];

//alert('shiparray length= ' + shiparray.length + '\nshiparray[1] = ' + shiparray[1] + '\nshiparray[2] = ' + shiparray[2] + '\nshiparray[3] = ' + shiparray[3] + '\nshiparray[4] = ' + shiparray[4] + '\nshiparray[5] = ' + shiparray[5] + '\nshiparray[6] = ' + shiparray[6] + '\nshiparray[7] = ' + shiparray[7] + '\nshiparray[8] = ' + shiparray[8]);
}

// shipping details object creation

ship_details = new shipp_details();

function shipp_details()
{

this.f_namea = ''
this.l_namea= ''
this.ad_onea = ''
this.ad_twoa = ''
this.citya = ''
this.statea =''
this.zipa = ''
this.countrya = ''
this.phonea = ''
this.faxa = ''
this.mailon = false
this.sameflag = false
this.shipname=''
this.ad_oneb = ''
this.ad_twob=''
this.shipb = ''
this.stateb=''
this.zipb=''
this.countryb=''
this.phoneb=''
this.faxb=''
this.email=''
this.comments = ''
}

function refresh_ship_details(shipform)
{
parent.main.document.order.comments.value = shipform.comments
parent.main.document.order.name_first.value= shipform.f_namea
parent.main.document.order.name_last.value= shipform.l_namea
parent.main.document.order.email.value=shipform.email
parent.main.document.order.address1.value=shipform.ad_onea
parent.main.document.order.address2.value=shipform.ad_twoa
parent.main.document.order.city.value=shipform.citya
parent.main.document.order.state.value=shipform.statea
parent.main.document.order.zip.value=shipform.zipa
parent.main.document.order.country.value=shipform.countrya
parent.main.document.order.phone.value=shipform.phonea
parent.main.document.order.fax.value=shipform.faxa
parent.main.document.order.mail_list.value=shipform.mailon
parent.main.document.order.same_flag.value=shipform.sameflag
parent.main.document.order.ship_name.value=shipform.shipname
parent.main.document.order.ship_address1.value=shipform.ad_oneb
parent.main.document.order.ship_address2.value=shipform.ad_twob
parent.main.document.order.ship_city.value=shipform.shipb
parent.main.document.order.ship_state.value=shipform.stateb
parent.main.document.order.ship_zip.value=shipform.zipb
parent.main.document.order.ship_country.value=shipform.countryb
parent.main.document.order.ship_phone.value=shipform.phoneb

}

function add_ship_details(shipform)
{

shipform.comments = parent.main.document.order.comments.value
shipform.f_namea = parent.main.document.order.name_first.value
shipform.l_namea= parent.main.document.order.name_last.value
shipform.email = parent.main.document.order.email.value
shipform.ad_onea = parent.main.document.order.address1.value
shipform.ad_twoa = parent.main.document.order.address2.value
shipform.citya = parent.main.document.order.city.value
shipform.statea =parent.main.document.order.state.value
shipform.zipa = parent.main.document.order.zip.value
shipform.countrya =parent.main.document.order.country.value
shipform.phonea = parent.main.document.order.phone.value
shipform.faxa = parent.main.document.order.fax.value
shipform.mailon = parent.main.document.order.mail_list.value
shipform.sameflag = parent.main.document.order.same_flag.value
shipform.shipname=parent.main.document.order.ship_name.value
shipform.ad_oneb = parent.main.document.order.ship_address1.value
shipform.ad_twob=parent.main.document.order.ship_address2.value
shipform.shipb = parent.main.document.order.ship_city.value
shipform.stateb=parent.main.document.order.ship_state.value
shipform.zipb=parent.main.document.order.ship_zip.value
shipform.countryb=parent.main.document.order.ship_country.value
shipform.phoneb=parent.main.document.order.ship_phone.value
}

// end of shipping details object handling

function

They have: 5,633 posts

Joined: Jan 1970

They have: 5,633 posts

Joined: Jan 1970

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.