Archive for 19th June 2008

Some Insight Into The Document Object Model: How Forms Are Stored By JavaScript

Recently asked on Yahoo! Answers:

JavaScript Submit form?

Ok, I know of the function…

function submitform() {document.myform.submit();}

however, for this to work, I have to name my forms, also, if I want to use it multiple times on the same page, each funtion name must be unique.

Is there a way to replace a submit button with javascript without having to uniquely name each function, or name my forms? I’m just looking for a link replacement for the submit button. So, a submit button just sits at the end of the form and submits it’s data, can I just replace it with a link, no extra stuff except one function at the top of the screen?

Also, the form’s method is POST, not GET. Also, the action is $PHP_SELF; though, if you give me an ideal answer, the JavaScript won’t even worry about the action.

This is something I don’t see as often as I’d like: A question about how something works, and a question with a practical application.

In other words, the user wants to solve a particular problem, but the question is posed in a way that its answer can reveal a great deal about how the Document Object Model (DOM) works. And understanding how things work makes programming far easier, believe me.

I began answering the direct question of how to submit an unnamed form with JavaScript, but then decided that, because opportunities like this are so rare, I’d seize upon it and launch a full dissertation here.

Before we begin, I’m going to be tossing around some terms about how classes / objects work. If you’re new to programming, or at least object-oriented programming, and aren’t familiar with terms such as “property,” “method,” “event” or “namespace,” you’ll want to check out my earlier entry, titled “Objects (Classes) Explained In Very Simple Terms.”

Continue reading ‘Some Insight Into The Document Object Model: How Forms Are Stored By JavaScript’ »