3

I want to call a Javascript function every time a checkbox changes its value. I do the same for inputs of the select type and there it works just fine. Both inputs are in one table. This is one element that calls the first function:

<td>
    <select name="minuteEnd" id="minuteEnd" onChange="calculateWorkTime()">'.$dropDown_minuteEnd.'
    </select>
</td>

And the part which calls the second function

<td>
    <input type="checkbox" name="deleteShift" id="deleteShift" onChange="updateSubmitButton()" /><br />
    <input type="checkbox" name="deleteShiftConfirm" id="deleteShiftConfirm" onChange="updateSubmitButton()" />.
</td>

Then I define both functions in separate script tags, but I also tried to define them in one, that did not solve the problem. Because I do not always need both of them I call a PHP-function for each to be written. These PHP functions are

drawScriptCalculateWorkTime();
drawScriptUpdateSubmitbutton();

the actual Javascript code is this:

function drawScriptCalculateWorkTime()
{
    echo'
    <script>
        function calculateWorkTime()
        {
            //I work (My name can be found)
        }
    </script>
    ';
}

function drawScriptUpdateSubmitbutton()
{
    echo'
    <script>
        function updateSubmitButton()
        {
            //I do not work. I get the error: ReferenceError: updateSubmitButton is not defined
            //This is my code
            var delete = document.getElementById("deleteShift").checked;
            var deleteConfirm = document.getElementById("deleteShiftConfirm").checked;

            if(delete && deleteConfirm)
            {
                document.getElementById("submitButton").disabled = false;
            }
        }
    </script>
    ';
}

My Browser-console always tells me

ReferenceError: updateSubmitButton is not defined,

but I checked the name about 20 times. Further, it always tells me on window load this:

SyntaxError: missing variable name

This refers to the first line of Code of the second javascript.

I already checked google and even found a quite similar question here ( Javascript Uncaught Reference error Function is not defined ) but that solution did not work for me.

If I did not provide all information needed I will provide them right away.

John

2
  • 2
    In javascript, delete is a reserved word and cannot be used for a variable name. Commented Sep 13, 2015 at 20:07
  • that actually did it. If you post it as an answer I can upvote it. Thanks a lot! Commented Sep 13, 2015 at 20:08

1 Answer 1

5

In javascript, delete is a reserved word and cannot be used for a variable name.

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

Comments

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.