jQuery: find id of of a form field
<p>I am creating a dynamic form where the user will have the ability to add a set of inputs to the form. The html looks like this:</p>

<pre><code>&lt;form&gt;
    &lt;input id="title1" class="title" name="title1"  type="text" value=""&gt;
    &lt;input id="productionCompany1" name="productionCompany1" type="text" value=""&gt;
    &lt;input id="year1" name="year1" type="text" value=""&gt;
    &lt;input id="role1" name="role1" type="text" value=""&gt;
&lt;div id="newCredit"&gt;&amp;nbsp;&lt;/div&gt;
&lt;a href="#" id="addCredit"&gt;add another credit&lt;/a&gt;
&lt;/form&gt;
</code></pre>

<p>When the user clicks the link with the id of "addCredit" the following jQuery script is called:</p>

<pre><code>$(document).ready(function() {
    var $ac = $('#addCredit');
    $ac.click(function() { 
/* the following two lines are where the problem lies? */
        var $credInt = $(this).prev(".title"); 
     $.get("addCredit.php", {num: $credInt},
     function(data){
     $('#newCredit').append(data);});
        return false;
    });
});
</code></pre>

<p>The jQuery function queries a php file called "addCredit.php", which looks like this:</p>

<pre><code>&lt;?php 
$int = $_GET["num"];
$int = substr($int, -1); 
$int++;
?&gt;
&lt;input id="title&lt;?php echo $int;?&gt;"  class="title" name="title&lt;?php echo $int;?&gt;"  type="text" value=""&gt;
&lt;input id="productionCompany&lt;?php echo $int;?&gt;" name="productionCompany&lt;?php echo $int;?&gt;" type="text" value=""&gt;
&lt;input id="year&lt;?php echo $int;?&gt;" name="year&lt;?php echo $int;?&gt;" type="text" value=""&gt;
&lt;input id="role&lt;?php echo $int;?&gt;" name="role&lt;?php echo $int;?&gt;" type="text" value=""&gt;
</code></pre>

<p>My problem is getting the javascript variable $credInt set properly so that it can be sent to the addCredit.php page and update the form fields accordingly. I also need to be sure that every time the form is appended, the next value sent is the incremented value.</p>

<p>Any thoughts on how I might accomplish this? Thank you for your help.</p>
