Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

InnerHTML Endless Loop Error

4 views
Skip to first unread message

MC

unread,
Dec 17, 2009, 2:31:45 PM12/17/09
to
Hi,

I am trying to process all of the input values in a form into the innerHTML.
When I set the following for input elements, it goes into an endless loop. I
have debugged in Firefox and can see it but not why. It acts like its
inserting a new input element instead of putting a value into it.
Any ideas?

function doText(myForm) {
var e, i = 0;
while (e = myForm.elements[i++]) {
if (e.type == 'text') e.innerHTML = e.value;
}
}

Thank you,
MC

This is from an example at
http://www.tizag.com/javascriptT/javascript-innerHTML.php "Updating text
based on user input"


Gregor Kofler

unread,
Dec 17, 2009, 3:12:37 PM12/17/09
to
MC meinte:

> Hi,
>
> I am trying to process all of the input values in a form into the innerHTML.
> When I set the following for input elements, it goes into an endless loop. I
> have debugged in Firefox and can see it but not why. It acts like its
> inserting a new input element instead of putting a value into it.
> Any ideas?
>
> function doText(myForm) {
> var e, i = 0;
> while (e = myForm.elements[i++]) {
> if (e.type == 'text') e.innerHTML = e.value;
> }
> }

Dunno. Setting the innerHTML of an input element here (FF with Firebug)
to "foo", "automagically" turns the innerHTML value into "<input>foo".
With an element without a meaningful innerHTML property (which in turn
isn't standardized anyway), everything's possible.

> This is from an example at
> http://www.tizag.com/javascriptT/javascript-innerHTML.php "Updating text
> based on user input"

In this very example the innerHTML of *another* element (with a
meaningful innerHTML value) is replaced. Putting some effort into
cutting and pasting might help.

Gregor


--
http://www.gregorkofler.com

MC

unread,
Dec 17, 2009, 3:22:14 PM12/17/09
to
Is there a way to set the value of the input element such that getting the
innerHTML of the form shows the value? A user inputted value does not show
when you get the form innerHTML and this is the problem I am trying to
solve.

MC


David Mark

unread,
Dec 17, 2009, 3:34:20 PM12/17/09
to

el.defaultValue = 'lookatme';

Gregor Kofler

unread,
Dec 17, 2009, 3:57:05 PM12/17/09
to
MC meinte:

Why do you want to access the form element value with innerHTML, when
there are dedicated element properties available?

Gregor


--
http://www.gregorkofler.com

MC

unread,
Dec 17, 2009, 4:00:37 PM12/17/09
to
Gregor,

Because I need the innerHTML of the form complete with all user input :) A
submit form will get the data but not the HTML.

MC


MC

unread,
Dec 17, 2009, 4:35:40 PM12/17/09
to

"David Mark" <dmark....@gmail.com> wrote in message
news:637c4174-77b0-481d...@r5g2000yqb.googlegroups.com...

el.defaultValue = 'lookatme';


David,

This does not work. I set the code to do as you suggest. It does not set the
value into the attribute 'value' for innerHTML.

MC

function getFormData(oForm) {


var e, i = 0;

while (e = oForm.elements[i++]) {
if (e.type == 'text') {
e.defaultValue = e.value;
}
}
}


MC

unread,
Dec 17, 2009, 4:40:07 PM12/17/09
to
David...

I forgot to actually call the function. This works BRILLIANTLY.

Thank you!
MC

PS. With this, we are able to take an html form and archive it as a
document. This is huge for us.


David Mark

unread,
Dec 17, 2009, 4:46:18 PM12/17/09
to

Dr J R Stockton

unread,
Dec 18, 2009, 3:11:48 PM12/18/09
to
In comp.lang.javascript message <hge5v1$8df$1...@newsreader2.utanet.at>,
Thu, 17 Dec 2009 21:57:05, Gregor Kofler <use...@gregorkofler.com>
posted:


Whole on or near the subject :

Given a reference to <a href="aa.htm">xxx yyy</a>, how best can one
(a) Obtain, as nearly as possible, 'xxx yyy' as in the source?
(b) Obtain, as nearly as possible, 'xxx yyy' as seen on the screen?
There, although 'xxx yyy' will commonly be short straight text, it may
contain other mark-up. I see innerHTML works in a simple case.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
<URL:http://www.merlyn.demon.co.uk/js-262-5.htm> -
first post-2009-12-04 editing pass, almost completed, on-line

Thomas 'PointedEars' Lahn

unread,
Dec 18, 2009, 7:21:49 PM12/18/09
to
Dr J R Stockton wrote:

> Gregor Kofler posted:


>> MC meinte:
>>> Is there a way to set the value of the input element such that
>>> getting the innerHTML of the form shows the value? A user inputted
>>> value does not show when you get the form innerHTML and this is the
>>> problem I am trying to solve.
>>
>> Why do you want to access the form element value with innerHTML, when
>> there are dedicated element properties available?
>
> Whole on or near the subject :
>
> Given a reference to <a href="aa.htm">xxx yyy</a>, how best can one
> (a) Obtain, as nearly as possible, 'xxx yyy' as in the source?
> (b) Obtain, as nearly as possible, 'xxx yyy' as seen on the screen?
> There, although 'xxx yyy' will commonly be short straight text, it may
> contain other mark-up. I see innerHTML works in a simple case.

This one was about form controls (confusingly named "form elements" here),
though. `A' elements are not form controls. And since form controls either
have no content (their content model is EMPTY, e.g. that of INPUT element's)
or they have content that is meaningless to the control's current value, one
would never, ever use the `innerHTML' property to retrieve that value. As
discussed, `outerHTML' may only be an option, maybe the only one, to work
around some quirks of buggy DOMs.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann

David Mark

unread,
Dec 19, 2009, 11:04:42 AM12/19/09
to
On Dec 18, 7:21 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:

Not really. I can only think of two obscure cases.

http://www.cinsoft.net/attributes.html

David Mark

unread,
Dec 19, 2009, 11:06:46 AM12/19/09
to
On Dec 18, 3:11 pm, Dr J R Stockton <reply0...@merlyn.demon.co.uk>
wrote:
> In comp.lang.javascript message <hge5v1$8d...@newsreader2.utanet.at>,

> Thu, 17 Dec 2009 21:57:05, Gregor Kofler <use...@gregorkofler.com>
> posted:
>
> >MC meinte:
> >> Is there a way to set the value of the input element such that
> >>getting the  innerHTML of the form shows the value? A user inputted
> >>value does not show  when you get the form innerHTML and this is the
> >>problem I am trying to  solve.
>
> >Why do you want to access the form element value with innerHTML, when
> >there are dedicated element properties available?
>
> Whole on or near the subject :
>
> Given a reference to <a href="aa.htm">xxx yyy</a>, how best can one
>   (a) Obtain, as nearly as possible, 'xxx yyy' as in the source?
>   (b) Obtain, as nearly as possible, 'xxx yyy' as seen on the screen?
> There, although 'xxx yyy' will commonly be short straight text, it may
> contain other mark-up.  I see innerHTML works in a simple case.
>

If you want it in interoperable form, you will need to write an
innerHTML wrapper. See My Library for an example. The first step is
to wrap the various attribute methods.

http://www.cinsoft.net/mylib.html

http://www.cinsoft.net/attributes.html

0 new messages