SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    0 Post(s)
    0 Thread(s)

    Exclamation Please help cant get print to work

    i have tried everything, you can see the print function when the program starts yet as soon as it finishes print has vanished

    why is this

    also when the program displays the result the variable displays the correct item except it has undefined next to it:

    here is my code please help:


    <title>Book Program</title>

    <script type="text/javascript">

    var book = new Array()
    var price = new Array();
    var total = 0;

    //this shows the prompt which allows the user to enter the information
    function show_prompt(){
    //this says that the variable i = o
    var i=0
    //this asks how many books have you sold and it then asks for the number of books depending on how many you entered
    booknum = parseFloat(prompt('how many books have you sold today'));
    for (i = 0; i < booknum; i++){
    book[i] = prompt("what is the name of the book?");
    //this asks you to enter the price of the items from the book
    price[i] = parseFloat(prompt('Enter price of item named :'+book[i]));
    //this displays the name and price of book on screen
    document.write("<br>"+"name:" + ' ' + book[i] + " " + "Price:" + price[i] + '<br/>' );
    //this totals the price variable
    document.write("<br>"+"Total Cost: " + total ); //displays the results



    <body onload = "document.write(show_prompt())">
    <form><input type="button" value=" Print Page "
    onclick="window.print();return false;" /></form>


    Reply With Quote

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Christchurch, New Zealand
    104 Post(s)
    4 Thread(s)
    When you use document.write on an already loaded page, the web browser removes that existing page and starts you off with a completely blank page.

    You will instead want to use standard DOM-manipulation techniques to add or update document elements of your existing page.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Posting Permissions

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