471,071 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

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="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?

Jul 23 '05 #1
2 2270
Justin Koivisto wrote:
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
Jul 23 '05 #2
DOH! Such a simply thing to overlook! Thanks a bunch!

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by micahl0180 | last post: by
8 posts views Thread by Chris Kettenbach | last post: by
2 posts views Thread by Sorrow | last post: by
8 posts views Thread by Mark Livingstone | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.