I am working on a simple javascript quiz and I canβt get Javascript for life to submit a form and open the result on the same page, regardless of whether I use location.href, open.window, or I set "_self" to as a goal. It doesn't seem to matter what I'm doing ...
Here is my javascript:
function answer(){ var response = document.getElementById('answer').value; if (response == "correctanswer") location.href('right.html'); else location.href('wrong.html'); }
Here is my 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 do when the user submits the form, they go to "right.html" if they typed correctanswer in the text box or "wrong.html" if they typed something else.
Everything works fine for me, except that no matter what I do, I can not get the resulting page to open in _self , but rather in another window. Everytime.
I drove me crazy all night.
source share