Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  39] [ 4]  / answers: 1 / hits: 27663  / 12 Years ago, sun, july 1, 2012, 12:00:00

Got 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 click the submit-button, the 'correct/wrong' shows only for a moment. I want it to stay on the site, any advice?


More From » javascript

 Answers
19

The submit buttons are submitting your form (so reloading your page).



Change the buttons to type=button.


[#84538] Friday, June 29, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emiliano

Total Points: 381
Total Questions: 109
Total Answers: 93

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
emiliano questions
;