I’m trying to load a page called "dual.php" using JavaScript, but it didn’t work.
Here is my JavaScript code that I use:
btnSubmitJoin.onclick = function() {
window.location.href = "dual.php";
}
I want to make it work like the HTML code that i use below:
<button style="--clr:#39FF14" onClick="parent.location='single.php'"><span>Single Player</span><i></i></button>
Anyone know how I can fix this?
I have try using window.location
, window.parent.location
, window.location.href
, and window.location.replace()
but it still didn’t work.
I hope someone can tell me where did I do wrong
Here is the screenshot for the details:
The JavaScript code that i use
The button
I want to make it work like this one but in JavaScript style
3
Answers
The correct way is like that:
if you want to make this over a Listener: (first delete onclick on HTML code)
javascript:
this is how it is done!
When you enclose your button in the form and the type is submit then the default behaviour when the button is clicked is to submit the form.
In your case when you are clicking on the button the enclosed form is getting submitted.
The solution is to prevent the default behaviour here.