tags:

views:

32

answers:

3

Hello, I have a quick question about JQuery. I have dynamically generated paragraphs with id's that are incremented. I would like to take information from that page and bring it to my main page. Unfortunately I am unable to read the dynamically generated paragraph IDs to get the values. I am trying this:

var Name = ((data).find("#Name" + id).text());

The ASP.NET code goes like this:

Dim intI As Integer = 0 

For Each Item As cItem in alProducts1 Dim pName As New System.Web.UI.HtmlControls.HtmlGenericControl("p") pName.id = "Name" & intI.toString() pName.InnerText = Item.Name controls.Add(pName) intI += 1 Next

Those name values are the values I want...Name1, name2, name3 and I want to get them individually to put in their own textbox... I'm taking the values from the ASP.NET webpage and putting them into an AJAX page.

A: 

Your question is not clear about your exact requirement but you can get the IDs of elements with attr method of jQuery, here is an example:

alert($('selector').attr('id'));
Sarfraz
A: 

You want to select all the elements with the incrementing ids, right?

// this will select all the elements
// which id starts with 'Name'
(data).find("[id^=Name]")
galambalazs
Forgive me for not writing things down so well. I want to find individual Id's. I.e. certain paragraphs will have different information in them which I will use to fill several textboxes and labels. I want to find the information based on the incrementing ID number to fill the web-form.
Daniel
have you tried what i suggested?
galambalazs
but your idea will find all id's that begin with the id name. I want id name1 to go into a one textbox, then name2 to go in another. So I want to take their values individually, instead of all together. It should look like this:var Name = ((data).find("#Name" + id).text());then I'll increment id (so id++;)var Name1 = ((data).find("#Name" + id).text());otherwise they come together in an array and I can get the values separated to put in their own inputboxes and labels.
Daniel
A: 

Thanks for the help everyone. I found the solution today however:

var Name = ($(data).find('#Name' + id.toString()).text());

I forgot the .toString() part and that seems to have made the difference.

Daniel