Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call javascript function from anchor html tag

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

like image 529
TestAnalyst Avatar asked Nov 28 '16 11:11

TestAnalyst


People also ask

How do you call a function in anchor tag?

First, you have to block href call URL if don't want to open the tab/window or other operations. You can call a function in 2 ways using the href or onclick attribute in the HTML tag.

Can we call JavaScript function in href?

In JavaScript, you can call a function or snippet of JavaScript code through the HREF tag of a link. This can be useful because it means that the given JavaScript code is going to automatically run for someone clicking on the link. HREF refers to the “HREF” attribute within an A LINK tag (hyperlink in HTML).

Can I use onclick in anchor tag?

Using onclick Event: The onclick event attribute works when the user click on the button. When mouse clicked on the button then the button acts like a link and redirect page into the given location. Using button tag inside <a> tag: This method create a button inside anchor tag.

Can we pass function in href?

The anwer is: not possible.


1 Answers

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

like image 175
Shivakrishna Avatar answered Oct 01 '22 08:10

Shivakrishna