File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes javascript:void() ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript:void() ??" Watch "javascript:void() ??" New topic
Author

javascript:void() ??

Saurabh Agrawal
Ranch Hand

Joined: Oct 07, 2003
Posts: 244
Hello friends ,
Currently i am working on a live project and was going through code of it.I found javascript:void() in the link of the anchor tag i.e.

<a id="recur_cal_enddate" href="javascript:void()"><img border="0" src="/valdero/img/general/calImage.gif" width="28" height="21" align="absmiddle"></a>

i.e. when i click the image a fucntion is called which shows the calender .

Now why this javascript:void() is called and what does it do ?

Hoping to get a good response.
Thanks,
Saurabh


Success is not doing extraordinary things but doing ordinary things extraordinarily well.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
it keepss the link from firing...If you did not have it, the page gets reloaded....

Eric
Jack Kay
Ranch Hand

Joined: Aug 01, 2004
Posts: 62
So I suppose this:
<a href="javascript:void">hello</a>

Is just another way to say this:
<a href="#">hello</a>

? Except without the page linking to the top of the page.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
The void method does not allow the link to do anything. The # reloads the page to the top since it is using an undefined anchor tag.

Eric
Jack Kay
Ranch Hand

Joined: Aug 01, 2004
Posts: 62
I can't get void() to work correctly, I get this error when the page loads:
Expected '('
line - 5
char - 13

I always get this error when click on hello:
Syntax error:
line - 1
char - 6

Jack Kay
Ranch Hand

Joined: Aug 01, 2004
Posts: 62
This works a whole lot better:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript:void() ??
 
Similar Threads
attributes with spaces
handling onclick
Servlets fails in Netscape
assign a function to the anchor via javascript.
html:link tag with javascript handler