How can you prototype the Form object?

P

phocis

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
 
M

Martin Honnen

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.
 
V

VK

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.onsubmit = function(){return mySubmit();}
}

?
 

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

Staff online

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top