Preserving input values in innerHTML with Mozilla

M

mypublicmail

I'm moving big chunks of html into and out of divs using innerHTML.
Or, I thought I was until I tested it on Firefox 1.5. Firefox will
move the html just fine, but if you have changed any input values in
that html (checkbox, radio, or text values), those new values won't
come along with the html --only their initial values when the html was
made. Internet Explorer 6 does bring the new values along with the
html. If I have to I can parse through the DOM and move all those
values over one-by-one, but I'm hoping there's a simpler solution
available. (I realize Microsoft made innerHTML and that it's still
proprietary --maybe that accounts for the "partial" implementation by
Mozilla.)

Thanks for your help,
Dennis
 
R

RobG

I'm moving big chunks of html into and out of divs using innerHTML.
Or, I thought I was until I tested it on Firefox 1.5. Firefox will
move the html just fine, but if you have changed any input values in
that html (checkbox, radio, or text values), those new values won't
come along with the html --only their initial values when the html was
made. Internet Explorer 6 does bring the new values along with the
html. If I have to I can parse through the DOM and move all those
values over one-by-one, but I'm hoping there's a simpler solution
available. (I realize Microsoft made innerHTML and that it's still
proprietary --maybe that accounts for the "partial" implementation by
Mozilla.)

I think you've answered your own question. Input and similar elements
have DOM attributes for value and default value, however only one can
be represented in HTML. The decision of which value to include seems
to be reflected in the innerHTML property and as you point out, the
lack of a standard means there's no consistency in that regard
(although having a standard may not help anyway :) ).

I guess you could write your own serialiser for converting such
elements from HTML to say JSON - add your own custom attribute for
default value to preserve the DOM defaultValue attribute and use the
current value as the value attribute.

Even if you do that, when you write it back to the page, how to you
deal with the value and default value thing?
 
M

mypublicmail

have DOM attributes for value and default value, however only one can
be represented in HTML. The decision of which value to include seems
to be reflected in the innerHTML property and as you point out, the
lack of a standard means there's no consistency in that regard
(although having a standard may not help anyway :) ).

I guess you could write your own serialiser for converting such
elements from HTML to say JSON - add your own custom attribute for
default value to preserve the DOM defaultValue attribute and use the
current value as the value attribute.

Even if you do that, when you write it back to the page, how to you
deal with the value and default value thing?

Thanks -- making a custom attribute (eg, 'newval') for each input
object is how I'll do it. When a user clicks on, say, a checkbox, I'll
call a JS function to set the attribute 'newval' to either 'checked' or
'unchecked'. Right after I innerHTML that code to its new home, I'll
loop through all the input objects and for any that have a
newval=checked or newval=unchecked, I'll use JS to manually check or
uncheck them. But it would have been cleaner if innerHTML would do
that for me automaticallly (as it does in IE6).
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top