OO JS and onsubmit - error: not a function

J

Justin Koivisto

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="myObject.testing()" ...

When I click the submit button for the form, I get the following
message in Mozilla's JavaScript Console:
"Error: myObject.testing 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.testing();
}

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?
 
D

Dietmar Meier

Justin said:
When I submit a form, I want to call it:
<form onsubmit="myObject.testing()" ...

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

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.testing)"> (cave:
no function calling round brackets!)
2) looking for other occurences of "myObject" in your document

ciao, dhgm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top