SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Urgent Help Arrays

    Hi can anyone help with this I am stuck on an assignment.
    I have one page with 3 iFrames in, each iFrame links to 3 seperate html. files, the code is as follows:

    "
    <html>
    <head>
    <title>Book Ordering System</title>
    </head>
    <body text="white" bgcolor="#666666" scroll="no">
    <br>
    <frameset>
    <table width = "990" height = "500" border="0" bgcolor="#CCCCCC" align="center">
    <tr>
    <td align="center"><iframe name="bookdisplay" height="462" src="bookdisplay.html"></iframe></td>
    <td align="center"><iframe name="orderdisplay" height="462" src="orderdisplay.html"></iframe></td>
    <td align="center"><iframe name="search" height="462" src="search.html"></iframe></td>
    </tr>
    </table>
    </frameset>
    </body>
    </html>"


    The frame on the left (book display) is suppost to show a list of all books found in the array called 'catalogue', which this does sucessfully, code follows :

    "<html>
    <head>
    <title>Untitled Document</title>
    </head>
    <body bgcolor="#FFFFFF">
    <script type="text/javascript">

    // define the catalogue
    var catalogue= new Array();
    catalogue[0]= new Array(3765834619,"Neuro-linguistic Programming for Dummies",12.99,950);
    catalogue[1]= new Array(5673423435,"Excel 2007 VBA Programming for Dummies",11.99,900);
    catalogue[2]= new Array(7454982674,"The Forgotten Garden",9.99,450);
    catalogue[3]= new Array(8356583865,"The Road Home",9.99,500);
    catalogue[4]= new Array(1629546824,"No Time For Goodbye",10.99,600);
    catalogue[5]= new Array(3547975624,"The Outcast",10.99,670);
    catalogue[6]= new Array(1348795463,"How to Write Songs on Guitar",15.99,1010);
    catalogue[7]= new Array(5673519472,"Fretboard Roadmaps",12.992,2700),
    catalogue[8]= new Array(2730471465,"Management and Organisational Behaviour",20.99,1000);
    catalogue[9]= new Array(4859716360,"Leadership Coaching",18.99,900);
    catalogue[10]= new Array(8455327034,"AA pocket world atlas",10.99,1000);
    catalogue[11]= new Array(7004367823,"The Years of Extermination ",8.99,450);
    catalogue[12]= new Array(6723002893,"Eden's Outcasts",10.99,900);
    catalogue[13]= new Array(5749438430,"What God Hath Wrought",10.99,800);
    catalogue[14]= new Array(6758465435,"Time and Materials",10.99,760);
    catalogue[15]= new Array(4356358907,"The Brief Wondrous Life of Oscar Wao",7.99,350);
    catalogue[16]= new Array(5837593750,"Harry Potter and the Deathly Hallows ",9.99,900);
    catalogue[17]= new Array(5759375974,"The World Without Us ",12.99,700);
    catalogue[18]= new Array(5847594738,"The Dangerous Book for Boys ",17.99,780);
    catalogue[19]= new Array(1477837381,"Deceptively Delicious",14.99,654);
    catalogue[20]= new Array(4543568745,"Dead Certain",14.99,500);
    catalogue[21]= new Array(7666834290,"Legacy of Ashes",11.99,1200);

    function show_books(){

    for ( i = 0; i < catalogue.length ; i++){

    document.write("<table>");
    document.write(" <tr>");
    document.write(" <td>" + catalogue[i][0] + "</td>");
    document.write(" </tr>");
    document.write(" <tr>");
    document.write(" <td>" + catalogue[i][1] + "</td>");
    document.write(" </tr>");
    document.write(" </table>");


    document.write("<table>");
    document.write(" <tr>");
    document.write(" <td>Price: </td>");
    document.write(" <td>" + catalogue[i][2] + "</td>");
    document.write(" </tr>");
    document.write(" <tr>");
    document.write(" <td>Weight: </td>");
    document.write(" <td>" + catalogue[i][3] + "g</td>");
    document.write(" </tr>");
    document.write("</table>");

    document.write("<table>");
    document.write(" <tr>");
    document.write(" <td>");
    document.write(" <form name='addtoorder'>");
    document.write("Quantity: <input type='text' width='2' name='quantity' value='1'/>");
    document.write(" </td>");
    document.write(" <td>");
    document.write(" <input type='submit' value='Add to Order' onclick=''/>");
    document.write(" </td>");
    document.write("</form>");
    document.write(" </tr>");
    document.write("<table>");

    document.write(" ----------------------------");

    }

    }
    show_books();

    </script>
    </body>
    </html>"

    Now i need (when the button is pressed) to get the data for that book and the quantity that is typed into the text box to be outputted onto the middle iFrame (displayorder) with the ability to output asmany or aslittle books. i was thinking maybe taking the values from the catalogue array and writing it to a new array called order on the display order page but i have no idea how to do this? any ideas?

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,263
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    Hi 123anderson123, welcome to the forums,
    What you are working with is a multidimensional array. Each of the catalogue array's values are also arrays. so it's something like
    catalogue[0][0] = 3765834619
    catalogue[0][1] = "Neuro-linguistic Programming for Dummies"
    catalogue[0][2] = 12.99
    catalogue[0][3] = 950
    catalogue[1][0] = 5673423435
    catalogue[1][1] = "Excel 2007 VBA Programming for Dummies"
    catalogue[1][2] = 11.99
    catalogue[1][3] = 900
    etc. etc.

  3. #3
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi many thanks,

    I understand what a multi dimensional array is I just don't understand how to get details of this array to a different web page in a different iframe.

    Can you help please?

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,263
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    To pass values you could use GET by adding a variable to a link
    So it depends, if you only want one of the books, it would probably be easier to make each a link with the values as a GET variable. But if more than one book, then each book could have a select option (checkbox) in a form and you could use GET to pass the values.
    Then use javascript in the orderdisplay.html to use the values in it's display using location.href see #12 http://www.sitepoint.com/forums/show...t=array+iframe

  5. #5
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks

    By using the GET function I am assuming ypu mean PHP.. but I can only use Javascript and DHTML.

    Is there any other way of doing it?

    Thanks for your responses I am really stuck on this bit.

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,263
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    GET is HTTP. It is passed to the server, and for a secure use, server-side handling is important. But javascript can access the URL string, eg.
    http://www.domain.com/page.html?GETvariable=value
    by getting the location.href property and parsing out the variable as shown in #12 (of the first post) of the sticky I previously linked to.


Bookmarks

Posting Permissions

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