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:

<html>
<head>

<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
total+=parseFloat(price[i]);
}
document.write(“<br>”+“Total Cost: £” + total ); //displays the results
}

</script>

</head>

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

</body>

</html>
Reply With Quote

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.