i want to sumbait to another page if counter > 5 can you please help me this is my code :
<p >
<span
id="display">0</span>
</p>
<script type="text/javascript">
var count = 0;
var disp = 0;
var btn = document.getElementById("btn");
var disp = document.getElementById("display");
btn.onclick = function () {
count ;
disp.innerHTML = count;
}
</script>
CodePudding user response:
You can do that with location.href = ""
.
<p >
<span id="display">0</span>
</p>
<script type="text/javascript">
var count = 0;
var disp = 0;
var btn = document.getElementById("btn");
var disp = document.getElementById("display");
btn.onclick = function () {
count ;
disp.innerHTML = count;
if (count > 5) {
location.href = "https://google.com/";
}
}
</script>
CodePudding user response:
btn.onclick = function () {
count ;
disp.innerHTML = count;
if(count > 5) {
//this will change the location of the window object aka. redirect
window.location.href = 'http://my_addreess.com';
}
}
CodePudding user response:
<p >
<span
id="display">0</span>
</p>
<button id='btn'>click</button>
<script type="text/javascript">
var count = 0;
var disp = 0;
var btn = document.getElementById("btn");
var disp = document.getElementById("display");
btn.onclick = function () {
count ;
disp.innerHTML = count;
if (count == 5)window.location.href="https://www.stackoverflow.com"
}
</script>