Javascript object is not a function

后端 未结 2 976
终归单人心
终归单人心 2020-12-21 23:40

I get the following error and I can\'t find why:

TypeError: object is not a function

Here is my html:

         


        
相关标签:
2条回答
  • 2020-12-22 00:13

    It appears the problem here is that you have a form element with the same name as your function:

    <td><input type="text" value="0" id="net_cash" name="net_cash"></td>
    

    So when you call net_cash() in your onkeyup event, it thinks you are referring to this input DOM object rather than the function of the same name. I suggest coming up with separate names for these two things.

    Inline event handlers have the enclosing <form> element as their executing scope. Each form control with a name attribute is treated as though it's a variable in that scope and that's where the conflict comes from.

    This is also yet another great reason to use unobtrusive JavaScript instead of inline event handlers. If you do that, you don't have to worry about your function names conflicting with your element names. See onclick=“” vs event handler for more information on the pitfalls of using inline event handlers.

    0 讨论(0)
  • 2020-12-22 00:14

    Your code is working fine for me. See demo here

    So make sure of the following

    1. Make sure that you are including the script before calling the function.
    2. Also, it is not a good idea to keep the ids/names and function names same

      <td><input type="text" value="0" id="net_cash" name="net_cash"></td>
      

      // Change the idand name here

    0 讨论(0)
提交回复
热议问题