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"
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
MC
el.defaultValue = 'lookatme';
Why do you want to access the form element value with innerHTML, when
there are dedicated element properties available?
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
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;
}
}
}
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.
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
> 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
Not really. I can only think of two obscure cases.
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.