I'm working on a simple javascript quiz, and I can't for the life of me get Javascript to submit the form and open the result in the same page, regardless of whether I use location.href, open.window, or whether I set _self as the target. Doesn't seem to matter what I do...
function answer() {
var response = document.getElementById('answer').value;
if (response == correctanswer)
location.href('right.html');
else
location.href('wrong.html');
}
<form onSubmit=answer() id=answer target=_self>
<input type=text maxlength=55 class=box autofocus />
<input type=submit class=submit value=SUBMIT />
</form>
So, what I want to happen is, when the user submits the form, they go to right.html if they typed correctanswer into the text box, or wrong.html if they typed anything else.
I've got it running fine, except for the fact that no matter what I do I can't get the resulting page to open in _self
, but rather in another window. Every time.
Been driving me crazy all night.