I am trying to use javascript functions within an calculated column which is working pretty fine e.g. if I use the following formula:
="<img src='/_layouts/images/blank.gif' onload=""{"
&" this.parentNode.innerHTML= new Date().toString() ;"
&"}"">"
This gets converted to the following html code on the site:
<td class="ms-vb-lastCell ms-cellstyle ms-vb2 ms-vb-lastCell">
<div align="right" class="ms-number">Fri Jun 17 11:36:29 UTC+0200 2016</div>
</td>
All fine with this. But when I declare and try to use a function, its not working anymore even its getting converted to an working javascript code.
I use the following formula:
="<script>"
&"function myfun(){"
&" return new Date().toString();"
&"}"
&"</script>"
&"<img src='/_layouts/images/blank.gif' onload=""{"
&" this.parentNode.innerHTML= myfun() ;"
&"}"">"
This gets converted to:
<td class="ms-cellstyle ms-vb2">
<div align="right" class="ms-number">
<script>
function myfun(){
return new Date().toString();
}
</script>
<img onload="{ this.parentNode.innerHTML= myfun();}" src="/_layouts/images/blank.gif">
</div>
</td>
But: the value is not displayed as you can see.
Any suggestions?