How to call JavaScript function instead of href in HTML

How to call JavaScript function instead of href in HTML

That syntax should work OK, but you can try this alternative.

n

<a href=javascript:void(0); onclick=ShowOld(2367,146986,2);>n

n

or

n

<a href=javascript:ShowOld(2367, 146986, 2);>n

n

UPDATED ANSWER FOR STRING VALUES

n

If you are passing strings, use single quotes for your functions parameters

n

<a href=javascript:ShowOld(foo, 146986, bar);>n

If you only have as click event handler, use a <button> instead. A link has a specific semantic meaning.

n

E.g.:

n

<button onclick=ShowOld(2367,146986,2)>n    <img title=next page alt=next page src=/themes/me/img/arrn.png>n</button>n

How to call JavaScript function instead of href in HTML

Try to make your javascript unobtrusive :

n

    n

  • you should use a real link in href attribute
  • n

  • and add a listener on click event to handle ajax
  • n

Leave a Reply

Your email address will not be published.