Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assinging JavaScript variable as a textbox id

 
devaki hanumante
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your string is not built right.

You have issues with " ' and +

Eric
 
devaki hanumante
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This works well. Hope it helps!
 
devaki hanumante
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks a lot...Its working now!!
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you understand WHY it is working?

Eric
 
devaki hanumante
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had not built the string correctly...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Utkarsh Jauhari,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic