Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > problem clearing innerhtml on mozilla

Reply
Thread Tools

problem clearing innerhtml on mozilla

 
 
ed
Guest
Posts: n/a
 
      12-01-2005
Hello-

i'm having some problems getting innerhtml to clear on mozilla, but it
works fine in ie. my page is setup such that i have a div:

<div id="otherModel"></div>

on a select from a combo box, in my javascript i execute:
div = document.getElementById("otherModel");
depending on what's selected in a combobox, i execute:
var inner2 = "<p>Other Model:<br />";
inner2 = inner2 + "<input type='text' id='otherModel' ";
inner2 = inner2 + "size='20' maxlength='30' value='Enter Model'>";
div.innerHTML = inner2;
or simply:
div.innerHTML = "test";

This all works fine independantly; it'll either fill with my textbox,
or the test string. but if the innerhtml is filled with the text box,
then i make a new selection that fills it with "test", it doesn't clear
out the text box.

If i replace the variable inner2 with simple text, everything seems to
work great (but i need a text box!). any insight would be
appreciated...

an example can be seen here:
http://www.atwistedweb.com/blog/inde...-Helmet-Survey.

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      12-02-2005
ed wrote:
> Hello-
>
> i'm having some problems getting innerhtml to clear on mozilla, but it
> works fine in ie. my page is setup such that i have a div:
>
> <div id="otherModel"></div>
>
> on a select from a combo box, in my javascript i execute:
> div = document.getElementById("otherModel");
> depending on what's selected in a combobox, i execute:
> var inner2 = "<p>Other Model:<br />";
> inner2 = inner2 + "<input type='text' id='otherModel' ";


Here you create a second element with the id 'otherModel', that gives
you invalid HTML.

> inner2 = inner2 + "size='20' maxlength='30' value='Enter Model'>";
> div.innerHTML = inner2;


A more efficient way of concatenating the text is:

var inner2 = "<p>Other Model:<br>"
+ "<input type='text' id='otherModel' "
+ "size='20' maxlength='30' value='Enter Model'>";


> or simply:
> div.innerHTML = "test";


You should implement this as something like:

var inner2 ='test';
if ( someTest ){
inner2 = "<p>Other Model:<br>"
+ "<input type='text' id='otherModel_02' "
+ "size='20' maxlength='30' value='Enter Model'>";
}
div.innerHTML = inner2;


In other words, set inner2 to some value and then change it if your
logic says to do so - and don't duplicate the ID.


> This all works fine independantly; it'll either fill with my textbox,
> or the test string. but if the innerhtml is filled with the text box,
> then i make a new selection that fills it with "test", it doesn't clear
> out the text box.


Probably because of the duplicated ID attribute.


>
> If i replace the variable inner2 with simple text, everything seems to
> work great (but i need a text box!). any insight would be
> appreciated...


Presumably replacing the HTML with simple text removed the duplicate ID.


> an example can be seen here:
> http://www.atwistedweb.com/blog/inde...-Helmet-Survey.


I looked, but it's messy. I think the above advice will do the trick.




--
Rob
 
Reply With Quote
 
 
 
 
ed
Guest
Posts: n/a
 
      12-02-2005

RobG wrote:
> ed wrote:
> > Hello-
> >
> > i'm having some problems getting innerhtml to clear on mozilla, but it
> > works fine in ie. my page is setup such that i have a div:
> >
> > <div id="otherModel"></div>
> > on a select from a combo box, in my javascript i execute:
> > div = document.getElementById("otherModel");
> > depending on what's selected in a combobox, i execute:
> > var inner2 = "<p>Other Model:<br />";
> > inner2 = inner2 + "<input type='text' id='otherModel' ";

>
> Here you create a second element with the id 'otherModel', that gives
> you invalid HTML.


that's it, that's rob! i'd been looking at the stooopid code all day
and it'd figure i'd miss something dumb like that!

<snip>
> > an example can be seen here:
> > http://www.atwistedweb.com/blog/inde...-Helmet-Survey.

>
> I looked, but it's messy. I think the above advice will do the trick.


yeah, it's all being dumped into the middle of a blog, so that doesn't
help... thanks for the hints though- it did the trick!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xhtml, innerHtml, appendChild, and innerHTML. what is the exact proper way to do this with DOM sonic Javascript 5 07-11-2006 08:17 AM
.innerHTML bug with mozilla/firefox (Ajax) Clément Javascript 6 04-11-2006 03:22 PM
getElementsByTagName, outerHTML, innerHTML in mozilla... Pai Javascript 3 05-03-2004 02:03 PM
Escaping quotes for innerHTML in Mozilla Ted Weatherly Javascript 1 03-03-2004 08:06 PM
Mozilla, innerHTML question. Mitch Javascript 4 09-17-2003 01:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57