• Resolved atrag

    (@atrag)


    The following code appears in a php file that is called from the content.php file using get_template_part.

    <div onclick="checkAllTopicCheckBoxes()"> </div>

    I added the following code to the bottom of the function.php file:

    function checkAllTopicCheckBoxes() {
        alert("Hello! I am an alert box!!");
    }

    When I click the element it returns:

    (index):363 Uncaught ReferenceError: checkAllTopicCheckBoxes is not defined.

    Can anyone please help me? At the moment I have it at the top of my the php file that is being called with get template within <script>. Is there any disadvantage to this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    This is JavaScript,not PHP,so it does not belong in your functions.php file

    function checkAllTopicCheckBoxes() {
        alert("Hello! I am an alert box!!");
    }

    You should put that in a .js file which would then be enqueued via wp_enqueue_script in functions.php

    Thread Starter atrag

    (@atrag)

    I am an idiot. Thank you 😉

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Onclick function “is not defined”’ is closed to new replies.