InnerHTML Endless Loop Error

M

MC

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"
 
G

Gregor Kofler

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
 
M

MC

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
 
D

David Mark

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.

el.defaultValue = 'lookatme';
 
G

Gregor Kofler

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?

Gregor
 
M

MC

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
 
M

MC

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.

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;
}
}
}
 
M

MC

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

Dr J R Stockton

In comp.lang.javascript message <[email protected]>,
MC meinte:

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

Thomas 'PointedEars' Lahn

Dr said:
Gregor Kofler 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.

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
 
D

David Mark

Dr J R Stockton wrote:






This one was about form controls (confusingly named "form elements" here),
though.  `A' elements are not form controls.  And since form controlseither
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.

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

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

David Mark

In comp.lang.javascript message <[email protected]>,



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
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top