Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7000309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:39:15+00:00 2026-05-27T20:39:15+00:00

I have the following html form, which is generated dynamically: <ul class=precursorList> <li> Precursor

  • 0

I have the following html form, which is generated dynamically:

<ul class="precursorList">
<li>
Precursor Name: <input name="precursorName" type="text">
    <ul class="portList">
      <li>Portname of precursor: <input name="precursorPort"  type="text">
          Portname of this: <input name="thisPort"  type="text">
      </li>
    </ul>
</li>
<li>       
<li>
Precursor Name: <input name="precursorName"  type="text">
    <ul class="portList">
      <li>Portname of precursor: <input name="precursorPort"  type="text">
          Portname of this: <input name="thisPort"  type="text">
      </li>
    </ul>
</li>
<li>   
</ul>

I want to get the values using jquery, therefore I have defined this loop:

ports = [];

$(".precursorList :input").each(function() {
    if(this.name == "precursorName") {
        var precursorName_ = this.value
        $(".portList :input ").each(function() {
            if(this.name == "precursorPort") {
                precursorPort_ = this.value;
            } else if(this.name == "thisPort") {
                ports.push({
                    filterName : precursorName_,
                    portNameOfFilter : precursorPort_,
                    portNameOfThis : this.value
                });
            }
        });
    }
});

Unfortunately this function does not work like I want it to work. The following loop $(".portList :input ").each( will always only loop over all elements in portList in the html document. How can I achieve that this loop will only loop over the corresponding portList, for each precursor?

UPDATE: The structure of the html element will stay the same only, the number of inputs will change. But there will only be a portList if a PrecursorElement exist.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:39:15+00:00Added an answer on May 27, 2026 at 8:39 pm

    id must be a unique field, instead use class to select multiple elements. Also use .live() for dynamically added elements.
    EDIT:
    If you are using Jquery > 1.7 use .on() instead of .live().
    I tried following and it seems that its working

       $(".precursorPort").each(function() {
            temp = this.name;
            $(this).parents(".portList").each(function() {
                $(this).parents(".precursorList").each(function() {
                    alert(temp);
                    // use temp var and save it in ports
                });
            });
        });
    

    Check this fiddle : http://jsfiddle.net/Ajinkya_Parakh/DR233/
    It may not be the best/most efficient but it is one of the working alternative.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following HTML: <form id=myform> <input type='checkbox' name='foo[]'/> Check 1<br/> <input
i have the following html code : <FORM name=frmmail> <input id=dochtmlContent type=hidden name=dochtmlContent value=oldValue/>
I have the following HTML: <form id=test> <input type=radio value=A name=C1/> <a href=javascript:selectCheckbox('C1', 'A');>
I have the following html: <html> <head></head> <body> <form> <input id=msg type=text value=oldValue />
I have the following HTML <form id=create_form name=create_form action= method=post> <input name=type id=type value=individuel
Suppose I have the following HTML form: <form> ... <input type=submit name=queue value=Queue item>
I have an HTML document with the following form: <form> <input type=text id=price> <input
I have following HTML with two elements having the same name <input type=hidden name=
I have a simple MVC form with the following elements: <%= Html.TextBox(FechaInicio) %> Which
I have the following HTML (removed some of the form input tags to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.