View Full Version : Putting total into another frame page

01-15-2004, 12:44 AM
Hi guys my first post here :)

I'm currently experimenting with an online shop (not a real one! :D) and am having trouble trying to display a total function in a different part of my frames page.

So I display the pages in a frame, on the left is a side menu (called side.html) and i have a main navigation page (main.html), I have multiple links on side.html (for the different components) and on each navigation page i have a total and quantity function. I would like to display the quantity function of all pages into the side menu.

Please could someone help me! Any help would be mucho appreciated i already tried to repeat the code i have so far from the total function but it doesn't seem to work! :(

Here is my code so far on the navigation page:



<script language="javascript">
var total = 0
var prices = new Array()
prices[1] = 69.95
prices[2] = 109.75
prices[3] = 136.00
prices[4] = 155.00

function resetQty(objSel,objText)

function calcTotal(iQty, iPrice, objTotal){
var localPrice= parseFloat(iPrice.substr(1));
objTotal.value=localPrice * iQty;
//cur = top.side.objTotal.allcosts.value.substring(1,top.side.objTotal.allcosts.value.length);
//tcur = ((cur * 1000) + (localprice * 1000)) / 1000;
//top.side.objTotal.allcosts.value = "" + tcur;

function showimage()
if (!document.images)
if(prices[document.mygallery.picture.selectedIndex] == null)
document.mygallery.price.value = ""
document.mygallery.price.value = "" + prices[document.mygallery.picture.selectedIndex]

function AddToCart(number)
price = prices[number]
if(price == null) price = 0
total = ((total*1000) + (price*1000)) / 1000

//cur = top.side.totalcosts.allcosts.value.substring(1,top.side.totalcosts.allcosts.value.length)
//tcur = ((cur * 1000) + (price * 1000)) / 1000
//top.side.totalcosts.allcosts.value = "" + tcur
document.mygallery.total.value = "" + total
document.mygallery.QTY.value = document.mygallery.price.value*QTY
//document.mygallery.VAT.value = document.mygallery.price.value*1.175



<table border="0" cellspacing="0" cellpadding="0">
<td width="100%">
<form name="mygallery">
<select name="picture" size="1" onChange="showimage(); resetQty(this.form.QTY, this.form.Total)">
<option value="">Please select</option>
<option value="abit_an7.jpg">Abit AN7 nForce2 (Socket A) Motherboard</option>
<option value="abitkv8max3.jpg">Abit KV8-MAX3 (Socket 754) Motherboard </option>
<option value="gigabyte.jpg">Gigabyte GA-8KNXP "Canterwood" (Socket 478) Motherboard</option>
<option value="gigabyte.jpg">Gigabyte GA-8INXP "Granite Bay" (Socket 478) Motherboard </option>
<select name="QTY" onChange="calcTotal(this.value,this.form.price.value, this.form.Total)">
<option value="1">1</option>
<option value="2">2</option>
<input type="text" name="price" size=6> <input type="text" name="Total" size="10" value="" readonly>
<input type="button" value="Add to basket" onClick="AddToCart(picture.selectedIndex)">

<td width="100%"><p align="center"><img src="blank.jpg" name="pictures" width="120" height="120">



01-15-2004, 06:26 AM
if the total will be put in a text field

top.frames['nameOfTargetFrame'].document.nameOfTargetForm.nameOfTargetField.value = total;

if in a <div> or </span>:


The important here is you know how to reference the frame


and then you can access the fields/variables in that frame the same way as in the same window/frame.

01-15-2004, 11:45 AM
... and for accesing an object or a function written or set in the main page, use the backward reference:

parent.document.... the rest of ref.

01-15-2004, 11:01 PM
Hi and thanks for the reply guys :)

sorry because I'm not very experienced with JavaScript I tried the following and haven't got it to work yet. i have put the

top.frames['nameOfTargetFrame'].document.nameOfTargetForm.nameOfTargetField.value = total;

into my quantity function. I am doing this right? So my side menu is called side.html and the result box (in side.html) is called allcosts. Many thx

My code so far:

function calcTotal(iQty, iPrice, objTotal)
top.frames[side].document.allcosts.objTotal.value = total;
var localPrice= parseFloat(iPrice.substr(1));
objTotal.value=localPrice * iQty;


01-19-2004, 06:22 AM
if the target frame is named side, the form is named myForm, the result textbox is named allcosts, the code should look like this:

top.frames['side'].document.myForm.allcosts.value = total;

If any name is wrong, change it appropriately.