简体   繁体   中英

Javascript reference error to function

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

在javascript中, delete是保留字,不能用于变量名。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM