4

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

0

2 Answers 2

13

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

Sign up to request clarification or add additional context in comments.

Comments

3

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.

1 Comment

Actually is does answer the question, it's just a really badly written answer from 4 years ago, no doubt when I was in a rush. Note "Tried changing the function name and that worked fine", also note the accepted answer above which involved changing the function name. In all probability d the accepted answer was posted whilst I was writing/testing things out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.