473,586 Members | 2,855 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem clearing innerhtml on mozilla

ed
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.getEle mentById("other Model");
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.

Dec 1 '05 #1
2 2281
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.getEle mentById("other Model");
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
Dec 2 '05 #2
ed

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.getEle mentById("other Model");
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!

Dec 2 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3410
by: -DRB- | last post by:
Hi all, I'm very much an amateur designing a page (for free!) for a friend, so any help offered would be hugely appreciated. I'm aiming to open a maximised window (and isn't that fun...) and found the following script on a freescripts page to do just that... it works perfectly. Into head section:
8
10890
by: Kyle | last post by:
I am presently making use of documentElement.innerHTML to retrieve page contents for manipulation, but I've noticed that the sting value returned is not identical to the actual page source. Specifically, attribute assignments that look like: height=100 width=100 in the real source, look like: height="100" width="100"
1
9049
by: Ted Weatherly | last post by:
Hello, I want to dynamically create a table cell with a textfield in it. The value for the textfield can have quotes. e.g. I have this snippet of javascript code: var td = document.createElement('td'); var cellMarkup = '<input value="&quot;test&quot;">'; td.innerHTML = cellMarkup;
38
3464
by: Luke Matuszewski | last post by:
Welcome I have read the in the faq from jibbering about the generic DynWrite, but i also realized that is uses only innerHTML feature of HTML objects. (1) Is there a DOM function which is very similar to innerHTML property eg. (my guess) setInnerNodeAsText or sth... ? I want to write function which will be dynamically updateing some of my...
8
7758
by: Clément | last post by:
Hi! I am currently developping a user interface with Ajax/C#/.net. And I am facing a problem with Mozilla, and Firefox. I use the function innerHTML to load a Web UserControl into a div, this way the main page never gets refreshed. It works perfectly under IE, but with Mozilla and Firefox I got a problem : there is a space before the...
3
6340
by: manolopm | last post by:
Hi: I'm trying something very simple. This works as it should in Firefox and Mozilla but in IE gives me an runtime error. The following code is the problematic code: <!DOCTYPE HTML PUBLIC "-//W3C//dtd HTML 4.01 Transational// EN""> <html> <head>
6
10916
by: Shigun | last post by:
On a website I am working on I am trying to load another page into a div on the the page the user does his work from. What I have works correctly in FireFox, but not in IE. I've rummaged Google for quite a bit and found similar problems, but no actual solutions. Here is the JavaScript I have to load a URL into a Div: function...
2
2517
by: swethak | last post by:
Hi, i am getting the problem when i used the onclick event in option tag.It is working fine in mozilla .But it is not working IE. Here is my code <script>
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.