call javascript function from anchor html tag

TestAnalyst picture TestAnalyst · Nov 28, 2016 · Viewed 89.8k times · Source

I need to display message when the user clicks link

How can I implement something where once the user click the hyper link on Page1, a "processing..." message and then as soon as Page2 is ready it forwards to Page2?

It is working for button click which I earlier posted got response implemented successfully.Thanks.

Hidden DOM element containing the message and to make it visible

Same thing I tried to implement for the below HTML code which is using Servlet not sure how to implement

        <a href="<%=request.getContextPath()%>/servlet/VisibilityController?searchType=workSearchDetails&workNo=<%=installAtLocListBean.getWorkNumber()%>&ID=<%= firstLocationNumber %>&sitePosition=<%=pagePosition%>"><%=installAtLocListBean.getWorkNumber()%>onclick="MyFunction();return true;"</a></td>

Can any body help me is it possible to do as button click any examples please Thanks in advance

Answer

Shivakrishna picture Shivakrishna · Nov 28, 2016

You can use either

<a href="javascript:someFunction()">LINK</a>

or

<a href="#" onclick="someFunction(); return false;">LINK</a>

or you can check this link. anchor tag onclick function