Text quickly disappears after clicking send
There was a problem. this is my code:
<html> <body> <form> <p>13-7: <input id="in1" type="text"" /><input type="submit" onclick="check(6, 'in1', 'out1')" value="Tjek!"/></p> <p id="out1"></p> <p>20-7: <input id="in2" type="text"" /><input type="submit" onclick="check(13, 'in2', 'out2')" value="Tjek!" /></p> <p id="out2"></p> <script type="text/javascript"> function check(facit, input, output) { var answer, evaluation; answer = document.getElementById(input).value; evaluation = (answer == facit) ? "Correct" : "Wrong"; document.getElementById(output).innerHTML = evaluation; return false; } </script> </form> </body> </html> When I press the submit button, right / wrong is only displayed momentarily. I want him to stay on the site, any tips?
+4
6 answers
The form is submitted and returned with the original page.
What do you want to do?
I dont want it returned with the original page .. I want it to say 'correct' og 'wrong' below the input If you do not want to send data, then do as minitech suggests, change the type from sending to the button.
If you want to save the data, you will need to write code on the server side, and then create html with these values populated (on the server side.)
0
<html> <body> <h1>What Can JavaScript Do?</h1> <p id="demo">JavaScript can change the style of an HTML element.</p> <input type="button" id="click me" value="clickme" onClick="action();" /> <script> var hidden = false; function action() { hidden = !hidden; if(hidden) { document.getElementById('demo').style.visibility = 'hidden'; } else { document.getElementById('demo').style.visibility = 'visible'; } } </script> </body> </html> 0