how to get the id of the text fields that is generated by dynamic addition of rows

I have an initial row contains some fields as I entered some values I am calculating some math and displaying the results in other fields
.Now I am adding a row dynamically by jquery by clicking + button .
My problem is now again I want to enter some values in the dynamically generated row and calculate the values and display it.
What do I need . I am thinking this can be done by incrementing the ids
reddyjc2011Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Prakash SamariyaIT ProfessionalCommented:
If you can add row dynamically, then you could also manipulate your it and pass that values to dynamic rows and provide ID to rows and its sub elements, so you can access that later on in javascript/jQuery!
Ray PaseurCommented:
Can you please show us the code you're using now?  It might be easier to give you a good example if we know where you're starting from.
karthik rajengineerCommented:
Hi Ray,

As prakash mentioned, you have to use sub elements. Here is a code sample.

<div id="template" style="display:none">
    <input id="field1" onchange="sum(this)"/>
    <input id="field2" onchange="sum(this)"/>

    <span id="result" style="width:50px;"></span>
    <button onclick="addRow()">+</button>
</div>

<div id="rows">

</div>

<script type="application/javascript" src="http://code.jquery.com/jquery.js"></script>

<script>
    $(function () {
        addRow();
    });

    function sum(currentObj) {
        var row = $(currentObj).parent();
        var field1 = row.find("#field1").val();
        var field2 = row.find("#field2").val();
        row.find("#result").text(field1 + field2);
    }

    function addRow() {
        $("#rows").append($("#template").clone().show());
    }
</script>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.