JavaScript Alert box not working before redirecting the user
up vote
1
down vote
favorite
<html>
<head>
</head>
<body>
<script>
function myFun()
var correct_way = /^[A-Za-z0-9]+$/;
var a = document.getElementById("User_Name").value;
if(a=="")
document.getElementById("Message").innerHTML="Please enter a username.";
return false;
if(a.length<5)
document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
return false;
if(a.match(correct_way))
alert.("Sucessful Login, welcome to BREAKOUT!");
document.location.href = "test1.html";
else
document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
return false;
return true;
</script>
<form action="test1.html" onsubmit="return myFun()">
<input type="text" id="User_Name" value=""></input>
<br></br>
<span id="Message"> </span>
<br></br>
<input type="submit" value="Submit"></input>
</form>
</body>
</html>
Hello, I have created a username validation code. The validation does work however, the user is not redirected to the 'test1.html' document. They are both in the same folder. How do i make it redirect after the validation is checked?
javascript html html5
add a comment |
up vote
1
down vote
favorite
<html>
<head>
</head>
<body>
<script>
function myFun()
var correct_way = /^[A-Za-z0-9]+$/;
var a = document.getElementById("User_Name").value;
if(a=="")
document.getElementById("Message").innerHTML="Please enter a username.";
return false;
if(a.length<5)
document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
return false;
if(a.match(correct_way))
alert.("Sucessful Login, welcome to BREAKOUT!");
document.location.href = "test1.html";
else
document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
return false;
return true;
</script>
<form action="test1.html" onsubmit="return myFun()">
<input type="text" id="User_Name" value=""></input>
<br></br>
<span id="Message"> </span>
<br></br>
<input type="submit" value="Submit"></input>
</form>
</body>
</html>
Hello, I have created a username validation code. The validation does work however, the user is not redirected to the 'test1.html' document. They are both in the same folder. How do i make it redirect after the validation is checked?
javascript html html5
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
<html>
<head>
</head>
<body>
<script>
function myFun()
var correct_way = /^[A-Za-z0-9]+$/;
var a = document.getElementById("User_Name").value;
if(a=="")
document.getElementById("Message").innerHTML="Please enter a username.";
return false;
if(a.length<5)
document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
return false;
if(a.match(correct_way))
alert.("Sucessful Login, welcome to BREAKOUT!");
document.location.href = "test1.html";
else
document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
return false;
return true;
</script>
<form action="test1.html" onsubmit="return myFun()">
<input type="text" id="User_Name" value=""></input>
<br></br>
<span id="Message"> </span>
<br></br>
<input type="submit" value="Submit"></input>
</form>
</body>
</html>
Hello, I have created a username validation code. The validation does work however, the user is not redirected to the 'test1.html' document. They are both in the same folder. How do i make it redirect after the validation is checked?
javascript html html5
<html>
<head>
</head>
<body>
<script>
function myFun()
var correct_way = /^[A-Za-z0-9]+$/;
var a = document.getElementById("User_Name").value;
if(a=="")
document.getElementById("Message").innerHTML="Please enter a username.";
return false;
if(a.length<5)
document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
return false;
if(a.match(correct_way))
alert.("Sucessful Login, welcome to BREAKOUT!");
document.location.href = "test1.html";
else
document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
return false;
return true;
</script>
<form action="test1.html" onsubmit="return myFun()">
<input type="text" id="User_Name" value=""></input>
<br></br>
<span id="Message"> </span>
<br></br>
<input type="submit" value="Submit"></input>
</form>
</body>
</html>
Hello, I have created a username validation code. The validation does work however, the user is not redirected to the 'test1.html' document. They are both in the same folder. How do i make it redirect after the validation is checked?
javascript html html5
javascript html html5
edited Nov 10 at 15:19
asked Nov 10 at 14:59
Rolls_Reus_0wner
114
114
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
You should return true
at the end of function myFun
.
HTML
<form action="test1.html" onsubmit="return myFun()">
<input type="text" id="User_Name" value="" />
<span id="Message"> </span>
<input type="submit" value="Submit" />
</form>
Updated code
function myFun()
var correct_way = /^[A-Za-z0-9]+$/;
var a = document.getElementById("User_Name").value;
if(a=="")
document.getElementById("Message").innerHTML="Please enter a username.";
return false;
if(a.length<5)
document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
return false;
if(a.match(correct_way))
alert("Sucessful Login, welcome to BREAKOUT!");
else
document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
return false;
return true;
jsFiddle demo - http://jsfiddle.net/h67q09mp/
thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
– Rolls_Reus_0wner
Nov 10 at 15:09
Where did you put the alert. Replace this linedocument.location.href = "test1.html";
with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s
– front_end_dev
Nov 10 at 15:15
So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
– Rolls_Reus_0wner
Nov 10 at 15:22
That's correct.
– front_end_dev
Nov 10 at 15:23
It does not appear!
– Rolls_Reus_0wner
Nov 10 at 15:27
|
show 2 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
You should return true
at the end of function myFun
.
HTML
<form action="test1.html" onsubmit="return myFun()">
<input type="text" id="User_Name" value="" />
<span id="Message"> </span>
<input type="submit" value="Submit" />
</form>
Updated code
function myFun()
var correct_way = /^[A-Za-z0-9]+$/;
var a = document.getElementById("User_Name").value;
if(a=="")
document.getElementById("Message").innerHTML="Please enter a username.";
return false;
if(a.length<5)
document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
return false;
if(a.match(correct_way))
alert("Sucessful Login, welcome to BREAKOUT!");
else
document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
return false;
return true;
jsFiddle demo - http://jsfiddle.net/h67q09mp/
thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
– Rolls_Reus_0wner
Nov 10 at 15:09
Where did you put the alert. Replace this linedocument.location.href = "test1.html";
with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s
– front_end_dev
Nov 10 at 15:15
So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
– Rolls_Reus_0wner
Nov 10 at 15:22
That's correct.
– front_end_dev
Nov 10 at 15:23
It does not appear!
– Rolls_Reus_0wner
Nov 10 at 15:27
|
show 2 more comments
up vote
1
down vote
You should return true
at the end of function myFun
.
HTML
<form action="test1.html" onsubmit="return myFun()">
<input type="text" id="User_Name" value="" />
<span id="Message"> </span>
<input type="submit" value="Submit" />
</form>
Updated code
function myFun()
var correct_way = /^[A-Za-z0-9]+$/;
var a = document.getElementById("User_Name").value;
if(a=="")
document.getElementById("Message").innerHTML="Please enter a username.";
return false;
if(a.length<5)
document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
return false;
if(a.match(correct_way))
alert("Sucessful Login, welcome to BREAKOUT!");
else
document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
return false;
return true;
jsFiddle demo - http://jsfiddle.net/h67q09mp/
thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
– Rolls_Reus_0wner
Nov 10 at 15:09
Where did you put the alert. Replace this linedocument.location.href = "test1.html";
with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s
– front_end_dev
Nov 10 at 15:15
So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
– Rolls_Reus_0wner
Nov 10 at 15:22
That's correct.
– front_end_dev
Nov 10 at 15:23
It does not appear!
– Rolls_Reus_0wner
Nov 10 at 15:27
|
show 2 more comments
up vote
1
down vote
up vote
1
down vote
You should return true
at the end of function myFun
.
HTML
<form action="test1.html" onsubmit="return myFun()">
<input type="text" id="User_Name" value="" />
<span id="Message"> </span>
<input type="submit" value="Submit" />
</form>
Updated code
function myFun()
var correct_way = /^[A-Za-z0-9]+$/;
var a = document.getElementById("User_Name").value;
if(a=="")
document.getElementById("Message").innerHTML="Please enter a username.";
return false;
if(a.length<5)
document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
return false;
if(a.match(correct_way))
alert("Sucessful Login, welcome to BREAKOUT!");
else
document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
return false;
return true;
jsFiddle demo - http://jsfiddle.net/h67q09mp/
You should return true
at the end of function myFun
.
HTML
<form action="test1.html" onsubmit="return myFun()">
<input type="text" id="User_Name" value="" />
<span id="Message"> </span>
<input type="submit" value="Submit" />
</form>
Updated code
function myFun()
var correct_way = /^[A-Za-z0-9]+$/;
var a = document.getElementById("User_Name").value;
if(a=="")
document.getElementById("Message").innerHTML="Please enter a username.";
return false;
if(a.length<5)
document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
return false;
if(a.match(correct_way))
alert("Sucessful Login, welcome to BREAKOUT!");
else
document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
return false;
return true;
jsFiddle demo - http://jsfiddle.net/h67q09mp/
edited Nov 10 at 15:36
answered Nov 10 at 15:02
front_end_dev
1,310411
1,310411
thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
– Rolls_Reus_0wner
Nov 10 at 15:09
Where did you put the alert. Replace this linedocument.location.href = "test1.html";
with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s
– front_end_dev
Nov 10 at 15:15
So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
– Rolls_Reus_0wner
Nov 10 at 15:22
That's correct.
– front_end_dev
Nov 10 at 15:23
It does not appear!
– Rolls_Reus_0wner
Nov 10 at 15:27
|
show 2 more comments
thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
– Rolls_Reus_0wner
Nov 10 at 15:09
Where did you put the alert. Replace this linedocument.location.href = "test1.html";
with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s
– front_end_dev
Nov 10 at 15:15
So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
– Rolls_Reus_0wner
Nov 10 at 15:22
That's correct.
– front_end_dev
Nov 10 at 15:23
It does not appear!
– Rolls_Reus_0wner
Nov 10 at 15:27
thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
– Rolls_Reus_0wner
Nov 10 at 15:09
thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
– Rolls_Reus_0wner
Nov 10 at 15:09
Where did you put the alert. Replace this line
document.location.href = "test1.html";
with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s– front_end_dev
Nov 10 at 15:15
Where did you put the alert. Replace this line
document.location.href = "test1.html";
with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s– front_end_dev
Nov 10 at 15:15
So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
– Rolls_Reus_0wner
Nov 10 at 15:22
So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
– Rolls_Reus_0wner
Nov 10 at 15:22
That's correct.
– front_end_dev
Nov 10 at 15:23
That's correct.
– front_end_dev
Nov 10 at 15:23
It does not appear!
– Rolls_Reus_0wner
Nov 10 at 15:27
It does not appear!
– Rolls_Reus_0wner
Nov 10 at 15:27
|
show 2 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240179%2fjavascript-alert-box-not-working-before-redirecting-the-user%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown