From: MC on
Hi,

I have a need to get the HTML code (and its state). I was thinking of doing
a

var e = document.getElementById("formName");

This will get a dom but not the html.
1. Is there an easy way to convert it to html?
2. Is there a better way to get the html with state?

MC


From: David Mark on
On Feb 9, 12:52 pm, "MC" <mica[removethis]@aisus.com> wrote:
> Hi,
>
> I have a need to get the HTML code (and its state). I was thinking of doing
> a
>
> var e = document.getElementById("formName");

It's more compatible to use document.forms.formName or
document.forms['formName'].

>
> This will get a dom but not the html.

Right.

> 1. Is there an easy way to convert it to html?

Well, you could get a reference to its parent and then get the
innerHTML property (in browsers that support it). Results vary cross-
browser though.

> 2. Is there a better way to get the html with state?

Depends on what you mean by state (i.e. does that include user
input?). You can certainly traverse the DOM and build the string
yourself, but it is a non-trivial task due primarily to botched
attribute handling in MSHTML (IE).

There is an example of this on the My Library test page.
From: MC on
David Mark, my favorite javascript guy!

Yes, I am trying to get the user input from checkbox, radio, input, and
select. It seems the input is retrieved via innerHTML but the other is not.

Mica

"David Mark" <dmark.cinsoft(a)gmail.com> wrote in message
news:c921385a-6b8b-48b9-8eed-930c4e9edc74(a)r10g2000vbn.googlegroups.com...
On Feb 9, 12:52 pm, "MC" <mica[removethis]@aisus.com> wrote:
> Hi,
>
> I have a need to get the HTML code (and its state). I was thinking of
> doing
> a
>
> var e = document.getElementById("formName");

It's more compatible to use document.forms.formName or
document.forms['formName'].

>
> This will get a dom but not the html.

Right.

> 1. Is there an easy way to convert it to html?

Well, you could get a reference to its parent and then get the
innerHTML property (in browsers that support it). Results vary cross-
browser though.

> 2. Is there a better way to get the html with state?

Depends on what you mean by state (i.e. does that include user
input?). You can certainly traverse the DOM and build the string
yourself, but it is a non-trivial task due primarily to botched
attribute handling in MSHTML (IE).

There is an example of this on the My Library test page.


From: MC on
Correction:
The user input from an input is in innerHTML but radio, checkbox, and select
user input is not.


From: David Mark on
On Feb 9, 1:20 pm, "MC" <mica[removethis]@aisus.com> wrote:
> David Mark, my favorite javascript guy!

Hey!

>
> Yes, I am trying to get the user input from checkbox, radio, input, and
> select.

There are inputs, selects and textareas (checkbox and radio are
_types_ of inputs).

> It seems the input is retrieved via innerHTML but the other is not.
>

The results of that proprietary property are implementation
dependant. You will have to traverse the DOM and use the checked,
value and selectedIndex properties to determine the states of the form
controls. It sounds as if the browsers you tested were referencing
the defaultChecked and defaultSelected properties for radio/checkbox
inputs and select options, but not the defaultValue property for text
inputs. That's certainly an incongruous approach.

Also, if you must deal with multi-selects, there is no single property
to reference (you have to loop through the options and check the
selected property for each).

And I've got to ask, what is the purpose of this? Seems like a can of
worms that doesn't need to be opened.

Please don't top-post. It screws up the context of the dicussion (and
I don't care to restore it).