wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Assinging JavaScript variable as a textbox id Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Assinging JavaScript variable as a textbox id" Watch "Assinging JavaScript variable as a textbox id" New topic
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: 15376
    
    6
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: 15376
    
    6
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: 60794
    
  65

Utkarsh Jauhari,
Your post was moved to a new topic.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assinging JavaScript variable as a textbox id
 
Similar Threads
Pattern for roles ?
translate from English to Hindi
Using a Variable with AJAX
dynamic text box value into database
Interfacing with SWF movie not working with firefox