User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 425,822 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,983 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 540 | Replies: 2 | Solved
Reply
Join Date: Feb 2007
Posts: 56
Reputation: adaykin is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
adaykin adaykin is offline Offline
Junior Poster in Training

Creating elements with dynamic id's in IE

  #1  
Jul 12th, 2008
Hello, I have done this successfully in firefox, but I need to do this in IE now, I want to dynamically generate an id for my input elements for an element being created. So far I can't get the id to come out correctly, here is what I have:

var i = 1;
while(i < 10)
{
var rowItem = document.createElement("<input type=text id=['up' + i]>");
tdItem.appendChild(rowItem);
i++;
}

so I would want the id's for my input elements to be up1, up2, up3, up4, etc.
My Website <-- check out my site!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 770
Reputation: R0bb0b is on a distinguished road 
Rep Power: 2
Solved Threads: 63
R0bb0b's Avatar
R0bb0b R0bb0b is online now Online
Master Poster

Re: Creating elements with dynamic id's in IE

  #2  
Jul 12th, 2008
Originally Posted by adaykin View Post
var rowItem = document.createElement("<input type=text id=['up' + i]>");


try this:
  1. var inputid = "up" + i;
  2. var rowItem = document.createElement('<input type="text" id="' + inputid + '">');

and according to what I've read here, you need to provide valid html for ie, yet that will throw an error in ff so you will have to check the browser type, refer here http://www.byteclub.net/wiki/index.p..._createElement
Last edited by R0bb0b : Jul 12th, 2008 at 5:57 pm.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
Reply With Quote  
Join Date: Feb 2007
Posts: 56
Reputation: adaykin is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
adaykin adaykin is offline Offline
Junior Poster in Training

Re: Creating elements with dynamic id's in IE

  #3  
Jul 12th, 2008
Thanks! That got it working, it works in both IE and Firefox, in Firefox I had to do

var rowItem = document.createElement('input');
rowItem.setAttribute('type', 'text');
rowItem.setAttribute('id', ['item' + l]);
My Website <-- check out my site!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 4:21 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC