473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

innerHTML input fields: IE vs FF

Hmm, I let the user add more input fields as needed. But I have a
strange problem with ff (and other mozillas)
When I add a field in ff, the others lost their content...
In IE the content stays
Is there a work-around for this?

this a piece of code to check this out:

<html>
<head>
<script type="text/javascript">
var counter = 0;
function doit(){
counter++;
document.getElementById('content').innerHTML += "<input type=\"text\"
id=\"field"+ counter +"\"/>";
}
</script>
</head>
<body>
<h1 id="header" onClick="doit()">Old header</h1>
<div id="content"><input type="text" id="jupse"/></div>
</body>
</html>

Feb 22 '06 #1
4 10468
d
"SimonV" <Si***************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hmm, I let the user add more input fields as needed. But I have a
strange problem with ff (and other mozillas)
When I add a field in ff, the others lost their content...
In IE the content stays
Is there a work-around for this?
Have you tried using createElement() and appendChild()? That, to my
knowledge, is the most robust way to add inputs to a page...

dave
this a piece of code to check this out:

<html>
<head>
<script type="text/javascript">
var counter = 0;
function doit(){
counter++;
document.getElementById('content').innerHTML += "<input type=\"text\"
id=\"field"+ counter +"\"/>";
}
</script>
</head>
<body>
<h1 id="header" onClick="doit()">Old header</h1>
<div id="content"><input type="text" id="jupse"/></div>
</body>
</html>

Feb 22 '06 #2
SimonV wrote:
Hmm, I let the user add more input fields as needed. But I have a
strange problem with ff (and other mozillas)
When I add a field in ff, the others lost their content...
In IE the content stays
You have discovered one of the differences between the implementation of
innerHTML in IE and Firefox - IE updates the value of the input in the
HTML, Firefox doesn't.

So when you read the innerHTML then write it back out again, IE keeps the
values that have been entered by the user, Firefox puts back the values in
the original source.

Is there a work-around for this?
Use DOM, not innerHTML.


this a piece of code to check this out:

<html>
<head>
<script type="text/javascript">
var counter = 0;
function doit(){
counter++;
document.getElementById('content').innerHTML += "<input type=\"text\"
id=\"field"+ counter +"\"/>";

Replace the line above with:

var div = document.getElementById('content');
var oI = document.getElementById('jupse').cloneNode(true);
oI.id = 'field' + counter;
oI.value = '';
div.appendChild(oI);

}
</script>
</head>
<body>
<h1 id="header" onClick="doit()">Old header</h1>
<div id="content"><input type="text" id="jupse"/></div> ------------------------------------------------^^^

Since you are using HTML, don't use XHTML-style empty element tag closures.

</body>
</html>

--
Rob
Feb 22 '06 #3
I see, thanks for the replys.
But in fact it's a little more complicated than that...
I set a table with some input fields in it. The cloning isn't the right
solution for this because fields can change
I get the table and its content in a string. The append child doesn't
work with a string...
what now?

Feb 22 '06 #4
Aha, I found a solution thats fine for me:

First I add a div to "jupse" and I give this div an id.
Then I use innerHTML on this new div to insert the string :-)

Feb 22 '06 #5

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

Similar topics

16
by: Joel Byrd | last post by:
I am having this ridiculous problem of trying to set the innerHTML of a div node. It works in all other browsers, but internet explorer is giving me an "Unknown runtime error". This is actually...
2
by: sveinn | last post by:
Hi all, I've read through this group searching for an answear about this problem. Few have come close but not quite what I need. My problem is this: I'm using Ajax to fetch a new table with...
7
by: Nez | last post by:
Help needed! Hello, I have looked everywhere for a solution to my problem and this is pretty much my last resource. I have created a table in a span with the innerhtml command in my code behind....
7
by: bobd314 | last post by:
Currently, I am having a problem replacing the value of a input box with something else using the innerHTML thing. Right now I have something going <script type="text/javascript"><!-- function...
2
by: mypublicmail | last post by:
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...
3
by: Marcin Domaslawski | last post by:
Hi, I've got simple script which adds to pointed DIV another DIV which contains 1 combobox (select) and textbox (input) - it's a AddNewRow() function. Every field has got unique ID (acording with...
1
by: Derek Basch | last post by:
I spent several hours struggling with dynamic form fields added with appendChild or innerHTML not POSTing on submit in Firefox. The only way I found to make it work is to append any created fields...
1
by: technod | last post by:
Hi, The error I am describing occurs with the script I've pasted below. It's a validator for form fields and prints a message into a span tag located beside the empty input tag. I have hard...
1
by: Buster | last post by:
Hello, First, this works fine in IE 6.5 and 7. Second, this is javascript embedded in ASP code. The purpose of this is to assign letters to form fields that are being rendered in an ASP loop. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...
0
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...

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.