[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I cancel a href in javascript?

Posted on 2005-04-13
3
Medium Priority
?
1,757 Views
Last Modified: 2011-10-03
I have a link like:

<a href=go_somewhere.htm onClick=doTest() return>Go</a>

I have JavaScript like:

function doTest(){
     return confirm("Click OK for next page, or click Cancel to stay on this page");
}

Using this construct it always goes to the next page regardless of which button is clicked in the JavaScript pop-up.
0
Comment
Question by:vogtster
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 1000 total points
ID: 13777480
try
<a href='go_somewhere.htm' onClick='return doTest();'>
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13777514
<a href="#" onClick=doTest();return false;>Go</a>

I have JavaScript like:

function doTest(){
  var a =   return confirm("Click OK for next page, or click Cancel to stay on this page");
if(a)
window.location.href = "go_somewhere.htm"
else
return false;
}
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13777519
u shud remove the return in the var a line

see here this example

<BODY>
 <a href="#" onClick=doTest();return false;>Go</a>

I have JavaScript like:
<script>
function doTest(){
  var a =   confirm("Click OK for next page, or click Cancel to stay on this page");
if(a)
window.location.href = "http://www.yahoo.com"
else
return false;
}
</script>
</BODY>
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question