By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,462 Members | 799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,462 IT Pros & Developers. It's quick & easy.

How can you prototype the Form object?

P: n/a
Hello, I'm writing a AJAX based content management system for kicks
(not for money), and I want to create a seemless integration of AJAX
and html forms.

Inorder to do this, I need to rewrite alot of the basic javascript
functionality of objects.

What I need to do... Is prototype the Form object's submit() function.
But I cannot figure out how.

E.G.
// This...
var new_string = 'asdf';
String.prototype.new_string_function = function () { alert('this is a
new string function'); };
// Yields an alert box whenever
new_string.new_string_function();
// Is called.

This method works for:
Window, Document, Object, and many other things. But not for Form. Why?
Am I just missing the Form's core class name? What could it be?

I've looked around for hacked core source codes of JS, but I can't find
any. So... Does anyone know how to nab this sucker's class name?

Many thanks,
Carl

Jan 12 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a


ph****@gmail.com wrote:

Am I just missing the Form's core class name? What could it be?


There are no classes in JavaScript 1.x. Inheritance for user defined
objects is prototype based. There is no requirement for host objects to
do and expose the same.
Mozilla in its DOM might expose
HTMLFormElement.prototype.submit
but don't expect that to be cross browser. IE/Win certainly does not
expose this.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 12 '06 #2

P: n/a
VK

ph****@gmail.com wrote:
What I need to do... Is prototype the Form object's submit() function.
But I cannot figure out how.


I guess you may overload Form element in Firefox (I never tried but
rumors are that it's possible).

You definitely cannot overload HTML elements in IE from within script.
The core difference between window / document and form is that both
window / document are host objects, and form is just uhm... simply
<form> element. Never was good on theory though.

You can force HTML elements to act bizarre in IE by attaching behavior
files to them (.htc)
In the context of the behavior file the core "element" object is being
exposed.

But maybe you would agree on something more easy and universal like:

function mySubmit() {
// return either true (submit)
// or false (don't)
}

var frm = document.getElementsByTagName('FORM');
for (var i=0; i<frm.length; i++) {
frm[i].onsubmit = function(){return mySubmit();}
}

?

Jan 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.