javascript - Print a word in my code -
this question has answer here:
- how concatenate string variable? 5 answers
i trying add 2 numbers in javascript , using below code given @ stack overflow website.
i want print output of file result =
. shows result without wordings before it. please let me know how display result result = $result$
<html> <body> <p>click button calculate x.</p> <button onclick="myfunction()">try it</button> <br/> <br/>enter first number: <input type="text" id="txt1" name="text1">enter second number: <input type="text" id="txt2" name="text2"> <p id="demo"></p> <script> function myfunction() { var y = document.getelementbyid("txt1").value; var z = document.getelementbyid("txt2").value; var x = +y + +z; document.getelementbyid("demo").innerhtml = x; } </script> </body> </html>
change line
document.getelementbyid("demo").innerhtml = x;
to
document.getelementbyid("demo").innerhtml = 'result=' +x;
as @marcell fülöp has pointed out, javascript , not java. there should heaps of information online know two.
just break down bit, document.getelementbyid("demo")
gets element (in case paragraph) in html document has id of demo
. .innerhtml =
letting put ever value want inside of demo
element.
Comments
Post a Comment