Connecting Tech Pros Worldwide Help | Site Map

Preserving input values in innerHTML with Mozilla

  #1  
Old January 24th, 2007, 09:35 PM
mypublicmail@adelphia.net
Guest
 
Posts: n/a
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

  #2  
Old January 25th, 2007, 07:25 AM
RobG
Guest
 
Posts: n/a

re: Preserving input values in innerHTML with Mozilla




On Jan 25, 7:24 am, mypublicm...@adelphia.net wrote:
Quote:
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?


--
Rob

  #3  
Old January 25th, 2007, 03:55 PM
mypublicmail@adelphia.net
Guest
 
Posts: n/a

re: Preserving input values in innerHTML with Mozilla




On Jan 24, 11:18 pm, "RobG" <r...@iinet.net.auwrote:
Quote:
On Jan 25, 7:24 am, mypublicm...@adelphia.net wrote:
>
Quote:
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?
>
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).

Closed Thread