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

getting the id of dynamically generated textboxes in using document.getElementById()

Hi,

Im adding textboxes dynamically from an onclick event that calls the function below:
function addRowDynamic()
{
rowCnt++;
lookupCnt++;
id++;
//add a row to the rows collection and get a reference to the new added row
var newRow = document.all("D").insertRow(rowCnt);

//add cells (<td>) to the new row and set the innerHTML

oneCell = newRow.insertCell();
var lookup= "image" + lookupCnt;
rowName = "DynamicValue" + rowCnt;
rowName = rowName.toString();

twoCell = newRow.insertCell();

twoCell.innerHTML = "<input type='text' name='" + rowName + "'
id='row "+ id +"'>
<a href='#'
onclick='javascript:showDynamicValuesNewRow(" + rowName +");return false'><img src='/rlms/images/lookup.gif' name='lookup' border='0' alt=''/></a> <a href='#' onclick='javascript:removeRowDynamic(this);return false'>Remove</a>";

var element = document.getElementById("row"+id).getAttribute("na me");
alert("id:"+element);
}

I have intialised rowCnt, lookupCnt, and id to 1 in the script... How do get the id of the new field ie. id='row"+id+"' using document.getElementById("row"+id).getAttribute("na me").
Currently im getting the error " document.getElementById("row"+id) is null or not an object".
Can you tell thet correct way of setting/getting the 'id'

Thanks.
Mar 27 '07 #1
3 7434
dorinbogdan
839 Expert 512MB
Remove the space when build the id string, so use:
Expand|Select|Wrap|Line Numbers
  1. id='row"+ id +...
instead of:
Expand|Select|Wrap|Line Numbers
  1. id='row "+ id +...
Mar 27 '07 #2
scripto
143 100+
I would try

id='row' + id.toString();

the problem is that getElementById only accepts strings, so convert the ID to a string first.
Mar 27 '07 #3
dorinbogdan
839 Expert 512MB
It's fine to convert to string, but in this case it's not required, since an implicit conversion occurs.

It should work with ("row"+id).

Scripter199, did you succeed to solve the problem?
Mar 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Martin | last post by:
There seems to be some strange behaviour when trying to get the scrollHeight and scrollTop of an iframe in IE6. I have tried several ways of getting these values when the iframe is written into...
6
by: Sjaakie | last post by:
Hi there, I'm trying to get this working with Firefox. Can you point out what's wrong? No problems with IE, Firefox doens't fill selMonth... TIA >>> the script... >>> <select name="selDay"...
1
by: adamredwards | last post by:
I have a page with some form elements that are dynamically generated. They are inserted into the dom by first cloning a node, changing the values like name, and then inserted with insertBefore(). ...
1
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works...
1
by: maya | last post by:
I'm using a function like this to load divs dynamically (and hide current one..) function get_img(curr_img,curr_nav,new_img,new_nav2) { var img_top = eval('document.getElementById(' +...
4
windows_mss
by: windows_mss | last post by:
When I Select Source & Destination Dynamically, Path Getting Scatter Across The Map... hi, i can able to get the Correct Route and Path for the corresponding Source and destination, like...
3
by: sakhan | last post by:
Hello Friends, I want to create a row of 10 textboxes each time I click the add button. I want this to continue till it reaches five hundred I am using AJAX for this. It doesnot create 10...
3
by: balurajeev | last post by:
Hii, currently i am working on an apliction(ASP.NET/C#) that creates dynamic html rows which contain six html text boxes and a html dropdowllist. At the time of page load the web page contain six...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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.