Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Location
    UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Putting total into another frame page

    Hi guys my first post here

    I'm currently experimenting with an online shop (not a real one! ) 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:

    <html>

    <head>

    <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)
    {
    objSel.selectedIndex=0;
    objText.value="";
    }

    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)
    return
    document.images.pictures.src=
    document.mygallery.picture.options[document.mygallery.picture.selectedIndex].value
    if(prices[document.mygallery.picture.selectedIndex] == null)
    document.mygallery.price.value = ""
    else
    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
    }


    </script>

    </head>

    <body>
    <table border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="100%">
    <form name="mygallery">
    <p>
    <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>
    <select name="QTY" onChange="calcTotal(this.value,this.form.price.value, this.form.Total)">
    <option>Quantity</option>
    <option value="1">1</option>
    <option value="2">2</option>
    </select>
    </p>
    Price:
    <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)">
    <br>


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


    </body>

    </html>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    if the total will be put in a text field

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


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

    top.frames['nameOfTargetFrame'].document.getElementById('idOfTargetDiv').innerHTML=total;

    The important here is you know how to reference the frame

    top.frames['nameOfTargetFrame']

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

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    ... 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.
    or
    parent.a_function()
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    New to the CF scene
    Join Date
    Jan 2004
    Location
    UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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;

    }

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •