Reputation: 344
I do have a calculated column in sharepoint which creates an anchor tag in which href have a javascript function call to test method but it's not getting called what i am missing here. Code :
<script type="text/javascript">
function test()
{
alert("hiii");
}
</script>
and calculated column :
<a href='javascript:test()'> Click </a>
Thanks in advance
Upvotes: 0
Views: 3551
Reputation: 456
If I understand, you need to change the display (html generated) of a field in SharePoint.
You are un 2013, you can use JSlink property of your field. With this, you can link a file JS to your field, and this file will be executed every time that sharepoint will generate the rendering of your field.
Check this link to understand how it work and see some exemples ;) : https://code.msdn.microsoft.com/office/Client-side-rendering-JS-2ed3538a
hope this will help you
Upvotes: 1
Reputation: 1058
Pure JS:
function test(){
alert("I am alerted");
}
<a onclick='test()' > Click </a>
jQuery
$(document).ready(function (){
$("#myID").on("click", function (){
alert("I am alerted !");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="myID" > Click </a>
Upvotes: 2
Reputation: 958
Please try this way:
<a href='javascript:void(0)' onclick='test()'> Click </a>
<script type="text/javascript">
function test()
{
alert("hiii");
}
</script>
Upvotes: 0
Reputation: 91
The attribute in the anchor you are looking for is called onclick
:
<a onclick="test()"> Click </a>
This should do the trick I guess. Check the w3c-schools site for a more detailed description: W3C Schools on the onclick HTML attribute
Upvotes: 0