473,405 Members | 2,154 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,405 software developers and data experts.

innerHTML not working in Firefox

Hi,

I'm writing an extensible form - it contains one name field to start and an
"Add another name" button, so you can add as many bnames as required and
then submit the form. Sounds simple and I have it working in IE5.5, but it
doesn't retain the data input to the form when run in Firefox. can anyone
please point me in the right direction? Code shown below...

Thanks in advance
Rae MacLeman

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Test Form</title>
<script language="JavaScript" type="text/javascript">
gCount = 1;
function addName(){
var el;
gCount++;
el = document.getElementById("myDiv");
el.innerHTML = el.innerHTML + "Enter Name : <input type='text'
name='fld"+gCount+"' id='fld" + gCount+"' size='10'><br>"
}
</script>
</head>

<body>
<form name="testform" id="testform">
<div id="myDiv">
Enter Name : <input type="text" name="fld1" id="fld1" size="10"><br>
</div>
</form>
<a href="javascript:addName();">Add another name field</a>
</body>
</html>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.772 / Virus Database: 519 - Release Date: 10/1/04


Jul 23 '05 #1
3 2128


webdev wrote:
I'm writing an extensible form - it contains one name field to start and an
"Add another name" button, so you can add as many bnames as required and
then submit the form. Sounds simple and I have it working in IE5.5, but it
doesn't retain the data input to the form when run in Firefox.


There are better ways doing this, use the W3C DOM API to create a new input
var input = document.createElement('input');
input.type = 'text';
input.name = 'inputName';
then to insert it where necessary e.g.
divReference.appendChild(input);
That should work with IE 5+, Netscape 6/7, Mozilla 1.x, Firefox, Opera 7
and doesn't cause the browser to reparse HTML that has already been
parsed into a DOM tree.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:41**********************@newsread2.arcor-online.net...


webdev wrote:
I'm writing an extensible form - it contains one name field to start and an "Add another name" button, so you can add as many bnames as required and
then submit the form. Sounds simple and I have it working in IE5.5, but it doesn't retain the data input to the form when run in Firefox.
There are better ways doing this, use the W3C DOM API to create a new

input var input = document.createElement('input');
input.type = 'text';
input.name = 'inputName';
then to insert it where necessary e.g.
divReference.appendChild(input);
That should work with IE 5+, Netscape 6/7, Mozilla 1.x, Firefox, Opera 7
and doesn't cause the browser to reparse HTML that has already been
parsed into a DOM tree.

--

Martin Honnen
http://JavaScript.FAQTs.com/


Thank you, Martin - that makes lots of sense, and I now have it working.

Regards
Rae MacLeman

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.772 / Virus Database: 519 - Release Date: 10/1/04
Jul 23 '05 #3
webdev wrote:
Hi,

I'm writing an extensible form - it contains one name field to start and an
"Add another name" button, so you can add as many bnames as required and
then submit the form. Sounds simple and I have it working in IE5.5, but it
doesn't retain the data input to the form when run in Firefox. can anyone
please point me in the right direction? Code shown below...

Thanks in advance
Rae MacLeman

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Test Form</title>
<script language="JavaScript" type="text/javascript">
gCount = 1;
function addName(){
var el;
gCount++;
el = document.getElementById("myDiv");
el.innerHTML = el.innerHTML + "Enter Name : <input type='text'
name='fld"+gCount+"' id='fld" + gCount+"' size='10'><br>"
}
</script>
</head>

<body>
<form name="testform" id="testform">
<div id="myDiv">
Enter Name : <input type="text" name="fld1" id="fld1" size="10"><br>
</div>
</form>
<a href="javascript:addName();">Add another name field</a>
</body>
</html>


The following works for me. The advantage of using cloneNode is that
you can put whatever you like in the <div> that gets cloned.

<html>
<head><title>Test Form</title>

<script type="text/javascript">
var gCount = 1;
function addName(theForm) {
gCount++;
var oldEl = document.getElementById("fred");
var newEl = oldEl.cloneNode(true);
theForm.insertBefore(newEl,oldEl.nextSibling);
}
</script>
</head>

<body>

<form name="testform" id="testform" action="">
<div id="fred">Enter Name :
<input type="text" name="fld1" id="fld1"
size="10"><br>
</div>
<input type="button" name="fred" value="Add a Name"
onclick="addName(this.form);"><br>
<input type="submit" value="submit">
</form>

</body>
</html>
Jul 23 '05 #4

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

Similar topics

14
by: catorcio | last post by:
I'm trying to have some text in my page changed by clicking a button. Googleing around I've discovered that innerText doesn't work with every browser, so I've switched to innerHTML. It works fine...
10
by: Jake Barnes | last post by:
This weekend I wanted to learn AJAX, so I set up a little toy page where I could experiment. The idea of this page is that you click in one of the boxes to get some controls, at which point you can...
9
by: Hallvard B Furuseth | last post by:
Why does the FAQ (Q 4.15) recommend innerHTML when so many here say one should use createElement(), replaceChild() etc? Also, why does the "Alternative DynWrite function" at...
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: Hoss | last post by:
Hello all- This is what im trying to achieve. At the top of my page there is some search functionality, through which you cause to be loaded a string representing an HTML page. Below this and...
4
by: tcole6 | last post by:
My problem appears to be Firefox specific. I have a hyperlink that loads a new window. This window contains hyperlinks that call javascript functions in the parent window and then closes the...
6
by: sonic | last post by:
Ok, i am sure everyone is sick of hearing about this. but i've checked about 10 different posts/sites about this issue, and they all say "use DOM" but i think there is more to be said. Perhaps I...
3
by: Fredyy | last post by:
i am simply updating the innerHTML of a TD with text (replacing '\n' with '<br />'). In firefox, if i add one line to the existing i.e. Changing: 123 Your Street Town, State 12345 To: 123...
6
omerbutt
by: omerbutt | last post by:
hi there i have a registration page on which i have a captcha verification method i customized that code for the sake that the user is able to refresh the captcha images by staying on the same page...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.