| Author |
Assinging JavaScript variable as a textbox id
|
devaki hanumante
Greenhorn
Joined: Jan 18, 2009
Posts: 13
|
|
Hi
I have the following piece of code which is called by clicking a button.I have a JavaScript variable 'i' which i want to assign as an id to the dynamically generated text boxes.
var i=1;
function add_buyer1()
{
i=i+1; div_buyer.innerHTML = div_buyer.innerHTML +"Buyer id : <input type='text' name='buyer' + i id='buyer' + i value=' ' > "
}
Now as the textboxes get added i want their names and id's to be buyer1,buyer2.....
How do I achieve that?
id='buyer' + i is not working
Thanking you in advance.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
Your string is not built right.
You have issues with " ' and +
Eric
|
 |
devaki hanumante
Greenhorn
Joined: Jan 18, 2009
Posts: 13
|
|
div_buyer.innerHTML = div_buyer.innerHTML +"<p>Buyer id : <input type='text' name='buyer' + i value=' ' id='buyer' + i></p>"
I didnt exactly get you
If i replace id='buyer' and name='buyer' then it is working fine
|
 |
Ryan Beckett
Ranch Hand
Joined: Feb 22, 2009
Posts: 192
|
|
This works well. Hope it helps!
|
 |
devaki hanumante
Greenhorn
Joined: Jan 18, 2009
Posts: 13
|
|
|
Hey thanks a lot...Its working now!!
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
Do you understand WHY it is working?
Eric
|
 |
devaki hanumante
Greenhorn
Joined: Jan 18, 2009
Posts: 13
|
|
|
I had not built the string correctly...
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56157
|
|
Utkarsh Jauhari, Your post was moved to a new topic.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: Assinging JavaScript variable as a textbox id
|
|
|