I want to have both href and onclick working and I found a solution here: HTML tag <a> want to add both href and onclick working
In myFunction, I make an AJAX Request calling a perl component.
It works fine when I put the Javascript call in href, but not when in onclick. Unfortunately, I'm not allowed this solution neither jQuery, so can you please help.
// AJAX Request doesn't work
<a href="www.mysite.com" onclick="myFunction();">Item</a>
<script type="text/javascript">
function myFunction () {
var xmlHttp = getXMLHttpObject();
xmlHttp.open('GET', 'perl.m', true);
return true;
}
</script>
// AJAX Request ok
<a href="javascript: myFunction('www.mysite.com')">Item</a>
<script type="text/javascript">
function myFunction (url) {
var xmlHttp = getXMLHttpObject();
xmlHttp.open('GET', 'perl.m', true);
window.location.href = goto_url;
}
</script>
perl.m:
<%init>
warn "perl.m";
... update ...
</%init>