This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript:void() ??

 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it keepss the link from firing...If you did not have it, the page gets reloaded....

Eric
 
Jack Kay
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works a whole lot better:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic