I am a beginner in JavaScript and HTML.
I am writing a code in JavaScript that converts “Infix to Postfix”.
The user enters their “desired mathematical expression” into a form (made by html), then presses a button to evaluate the solution of the infix expression.
But the program clears the page before it writes the solution.
I do NOT want the solution to appear on a cleared page. I want it to appear on the original page, in a textbox or anything else. But I can’t get the textbox to “output” anything.
Help please?
Most grateful.
To insert text into an existing textbox, you need to do two things.
There are many ways to get the DOM element of the textbox.
document.getElementById()is the simplest. You put an id=”whatever” attribute on your textbox HTML and then usedocument.getElementById("whatever")to get the DOM element.This is the simplest example:
HTML:
Javascript:
Working demo: http://jsfiddle.net/jfriend00/b4mNP/
Do NOT try to use
document.write()after the document has finished loading. That will just clear the existing document and start writing a new one.You also have to make sure that you don’t have a form that is doing a form submission (as that will also clear the page) and that you’re not clicking a link that will go to an href.