I am making a page where users can answer questions (using radio buttons) about a product they are selling back. When they hit a button at the bottom of the page, a price quote will pop up. I have written a javascript function to be performed when the user hits the button. It calculates the price and displays it using document.write, but whenever the user hits the button, it opens up a new page and displays what I told it to.
function getQuote(){
document.write("Your Quote Is: $", price, ".00");
}
And here is the code for the button:
<button type="button" onclick='getQuote()'>Display Quote</button>
But when I push the button, a new page shows up and it shows the quote with only the formatting I put into the document.write phrase.
I have tried using .innerHTML to send the document.write to another part of the page, but the same problem persists.
What can I do to make sure that the quote shows up on the page, where I want it to?
There is no issue with
document.write, it is doing exactly what it is supposed to do:If you do not want to do that, then you have to give it some context to write to.
For example:
Which puts whatever your text is into a DOM element with
id="textArea"