473,382 Members | 1,720 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,382 software developers and data experts.

Dynamic fields and refreshing throught innerHTML

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 script below). There is also
getNewDig(int) function, which change value of appropriate input field
(checks value of select field and put it to input e.g. if in Pr_1 value has
changed than that value is set to the Number_1 input).

Problem is, values of existing fields are refreshing when new row is added
(to check it: click Add New Row, set value in select field, click Add New
Row).

Problem does not occur with IE. I suppose it's caused by innerHTML which
refresh whole document.getElementById( 'Tutaj' ).

Page:
-----------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
<html>
<head></head>
<body>
<script language="javascript">
<!--

var obField;
var nCount = 0;

function AddNewRow()
{
nCount++;
var sForm = '<div id="Pr_' + nCount + '">';

sForm += '<select name="Number_' + nCount + '" onchange="getNewDig( ' +
nCount + ')">';
for ( var i = 1; i < 101; i++ )
{
sForm += '<option value="' + i + '">' + i + '</option>';
}
sForm += '</select>';
sForm += '<input type="text" name="Rice_' + nCount + '" /></div>';

document.getElementById( 'Tutaj' ).innerHTML += sForm;

getNewDig( nCount );

}

function getNewDig( id )
{
var nNumber = document.getElementsByName( 'Number_' + id )[0].value;
try
{
obField = document.getElementsByName( 'Rice_' + id )[0];
}
catch( e )
{
alert( e );
}
if ( obField )
obField.value = nNumber;
else
alert ( obField );
}

// -->
</script>

<a href="#" onclick="AddNewRow()">Add New Row</a>
<div id="Tutaj">
</div>

</body>
</html>
-----------------

How to solve it ? (I work with FF2.0.3)

-------
Marcin


Apr 26 '07 #1
3 3684
Marcin Domaslawski wrote :
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 script below). There is also
getNewDig(int) function, which change value of appropriate input field
(checks value of select field and put it to input e.g. if in Pr_1 value has
changed than that value is set to the Number_1 input).

try this:

var d=document

function AddNewRow()
{
var div=d.createElement("div");

var input=d.createElement("input");
input.type="text";

var select=d.createElement("select");
select.onchange=function(){input.value=this.value}
for (var i=1;i<101;i++)
select.add(new Option(i,i))

input.value=select.value
div.appendChild(select);div.appendChild(input)
d.getElementById('Tutaj').appendChild(div)
}

Apr 27 '07 #2

Uzytkownik "scripts.contact" <sc*************@gmail.comnapisal w
wiadomosci news:11**********************@c18g2000prb.googlegr oups.com...
Marcin Domaslawski wrote :
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 script below). There is also
getNewDig(int) function, which change value of appropriate input field
(checks value of select field and put it to input e.g. if in Pr_1 value
has
changed than that value is set to the Number_1 input).


try this:

var d=document

function AddNewRow()
{
var div=d.createElement("div");

var input=d.createElement("input");
input.type="text";

var select=d.createElement("select");
select.onchange=function(){input.value=this.value}
for (var i=1;i<101;i++)
select.add(new Option(i,i))

input.value=select.value
div.appendChild(select);div.appendChild(input)
d.getElementById('Tutaj').appendChild(div)
}
Hi,

It really works fine :)

I've added name attribute to input by input.name="Program1"; In completely
another function I'm trying to get this object by:
var objTest = document.getElementsByName( "Program1" )[0];
on FireFox it works fine. On IE I got objTest = null. I tried also
- document.getElementById( "Program1" );
- eval( "Program1" );
but IE gives me null on this object. Did I forget about something ?

Marcin Domaslawski

Apr 27 '07 #3
..Marcin Domaslawski wrote:
...
>
It really works fine :)

I've added name attribute to input by input.name="Program1"; In completely
another function I'm trying to get this object by:
var objTest = document.getElementsByName( "Program1" )[0];
on FireFox it works fine. On IE I got objTest = null.
hmm. that's strange. I can reproduce that here on my ie6 .
ID works.

Apr 27 '07 #4

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

Similar topics

2
by: Rosebud | last post by:
Hello, I'd like some help trying to generate input fields on the fly. What I have on an HTML page is a single text input field labelled #1, e.g. #1 <input type="text">. Next to the field is a...
0
by: Pat Sagaser via .NET 247 | last post by:
I'm using a repeater with a dynamic template. I don't know the fields to display (or how many) until runtime. I have everything working except for linking Button events to the repeaters ItemCommand...
0
by: Pat Sagaser via .NET 247 | last post by:
I'm trying to add LinkButtons to a Repeater control using adynamic template. The docs state that you should be able tobubble the click event to the containing Repeater. There areplenty of examples in...
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
ronnil
by: ronnil | last post by:
Just found an annoying thing in IE I'm working on this neat little form framework giving me easy-coded forms with some automatic made fields, for instance a boolean field. My original idea was...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
2
by: shorecreature | last post by:
I have a piece of js that creates a dynamic form .... simplified it's as follows... var oForm = document.getElementById('form'); var aData; // array of db values var table =...
1
by: chaitanyadotcom | last post by:
As per my application i need to create tabs using iFrame dynamically. There are totally 4 buttons in my application where for each button i provide a link. Where in it will dynamically create a tab...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.