Reputation: 23
i have this code
<a href="about.html" onclick="verify()"><span>go</span></a>
and i want when the verify complete as true
it's go to about.html
if not give alert
with the wrong and don't
go to about.html
Upvotes: 2
Views: 103
Reputation: 6605
<a href="about.html" onclick="return verify();"><span>go</span></a>
function verify(){
var isValid = false; // do your check!
if (!isValid) {
alert("some message");
}
return isValid;
}
Upvotes: 2
Reputation: 103135
The function verify should return false if you want to stop the link navigation. return true to continue to about.html.
e.g.
function verify(){
//verify stuff
if(it is verified){
return true;
}else{
alert("problems");
return false;
}
}
Upvotes: 2
Reputation: 116100
If verify
returns true
, it will jump the link. If it returns false
, you will not go to about.html. You can choose to show an alert if you like. It will not influence this flow.
Upvotes: 1