Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call javascript on checkbox onclick

I don't understand what I'm doing wrong here. I just want my function to be called when I click the checkbox. Replacing the function call with alert() works, am I referencing my function incorrectly?

<html>
<head></head>
<body>

<script type="text/javascript">
function select(a){
    document.getElementById("myDiv").innerHTML=""+a;
}
</script>

<input type="checkbox" onclick="select(1)">

<div id="myDiv">hi</div>

</body>
</html>

Thanks

like image 600
Dijkstra Avatar asked Dec 06 '22 01:12

Dijkstra


2 Answers

Change the function name [e.g. selectFun]. select seems to be reserved keyword

like image 66
Chinmayee G Avatar answered Dec 08 '22 03:12

Chinmayee G


This puzzled me as it looked ok to me too, So ran through the usual tests, eventually tried changing the function name and that worked fine.

like image 23
Kevin D Avatar answered Dec 08 '22 01:12

Kevin D