OO JS and onsubmit - error: not a function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Justin Koivisto

    #1

    OO JS and onsubmit - error: not a function

    This is probabally a basic question, but I don't quite understand what
    is going on with this...

    Say I have a variable called "myObject" which is an object created from
    a class I wrote. The class has a method called "testing".

    When I submit a form, I want to call it:
    <form onsubmit="myObj ect.testing()" ...

    When I click the submit button for the form, I get the following
    message in Mozilla's JavaScript Console:
    "Error: myObject.testin g is not a function"

    While trying to figure this out, I created a new function called
    "test_form" , and changed the form declaration to look like:
    <form onsubmit="test_ form()" ...

    Test form looks like this:
    function test_form(){
    myObject.testin g();
    }

    When I do this, the script works exactly as I had intended it to. Can
    any of you js experts tell me why that is?

  • Dietmar Meier

    #2
    Re: OO JS and onsubmit - error: not a function

    Justin Koivisto wrote:
    [color=blue]
    > When I submit a form, I want to call it:
    > <form onsubmit="myObj ect.testing()" ...
    >
    > When I click the submit button for the form, I get the following
    > message in Mozilla's JavaScript Console:
    > "Error: myObject.testin g is not a function"[/color]

    Probably you have another object or property named "myObject"
    which is found in the form element's scope chain before your
    requested object is found; this could be a form element named
    "myObject", for example.

    Try to find out what's happening by
    1) trying <form onsubmit="alert (myObject.testi ng)"> (cave:
    no function calling round brackets!)
    2) looking for other occurences of "myObject" in your document

    ciao, dhgm

    Comment

    • Justin Koivisto

      #3
      Re: OO JS and onsubmit - error: not a function

      DOH! Such a simply thing to overlook! Thanks a bunch!

      Comment

      Working...