Robin Robin - 6 months ago 32
HTML Question

img onclick call to javascript function

I am trying to make a img that when it is clicked a javascript function is called.
I have searched on the web but havent found anything that actually works(prob because of a mistake i made).

This code was made to pass javascript variables to a c# application.

Can anybody tell me what i am doing wrong?

<script type="text/javascript">
function exportToForm(a,b,c,d,e) {
window.external.values(a.value, b.value, c.value, d.value, e.value);
}
</script>
</head>
<body>
<img onclick="exportToForm('1.6','55','10','50','1');" src="China-Flag-256.png"/>
<button onclick="exportToForm('1.6','55','10','50','1');" style="background-color: #00FFFF">Export</button>
</body>

Answer

This should work(with or without 'javascript:' part):

<img onclick="javascript:exportToForm('1.6','55','10','50','1')" src="China-Flag-256.png" />
<script>
function exportToForm(a, b, c, d, e) {
     alert(a, b);
 }
</script>
Comments