Note that there are some explanatory texts on larger screens.

plurals
  1. POAppend numeric value to input name attribute with jQuery
    primarykey
    data
    text
    <p>I'm trying to add _1, _2 etc to the end of my input elements in a dynamic form. The user can add as many as they want I wrote this method but it seems to throw errors saying the "dName is undefined"</p> <pre><code>$j("#addBranch").click( function() { //see withDataAndEvents, copies events with bool in clone method $j('.branchOffice').first().clone(true).appendTo('#branchOffice'); $j('.branchOffice').last().children().attr('name',function() { var dName = $j(this.name).attr('name'); return dName.substring(0, dName.length-1) + ($j('.branchOffice').size() + 1) }); } ); </code></pre> <p>Here is the HTML</p> <pre><code>&lt;div class="leftPane"&gt; &lt;label for="company_name"&gt;Company Name&lt;/label&gt; &lt;input class="req" type="text" name="company_name" id="company_name" /&gt; &lt;label for="branch_office"&gt;Home Office&lt;/label&gt; &lt;input class="req" type="text" name="branch_office_1" id="branch_office_1" /&gt; &lt;label for="branch_office_add1_1"&gt;Address&lt;/label&gt; &lt;input class="req" type="text" name="branch_office_add1_1" id="branch_office_add1_1" /&gt; &lt;label for="branch_office_add2_1"&gt;Address 2&lt;/label&gt; &lt;input type="text" name="branch_office_add2_1" id="branch_office_add2_1" /&gt; &lt;label for="branch_office_city_1"&gt;City&lt;/label&gt; &lt;input class="req" type="text" name="branch_office_city_1" id="branch_office_city_1" /&gt; &lt;label for="branch_office_state_1"&gt;State&lt;/label&gt; &lt;select id="branch_office_state_1" name="branch_office_state_1"&gt; &lt;?php echo $formHelper-&gt;stateList; ?&gt; &lt;/select&gt; &lt;label class="naked" for="branch_office_zip_1"&gt;Zip&lt;/label&gt; &lt;input class="req zip" type="text" name="branch_office_zip_1" id="branch_office_zip_1" /&gt; &lt;/div&gt; &lt;div class="rightPane" id="branchOffice"&gt; &lt;div class="branchOffice"&gt; &lt;label for="branch_office_2"&gt;Branch Office&lt;/label&gt; &lt;input class="req" type="text" name="branch_office_2" id="branch_office_2" /&gt; &lt;label for="branch_office_add1_2"&gt;Address&lt;/label&gt; &lt;input class="req" type="text" name="branch_office_add1_2" id="branch_office_add1_2" /&gt; &lt;label for="branch_office_add2_2"&gt;Address 2&lt;/label&gt; &lt;input type="text" name="branch_office_add2_2" id="branch_office_add2_2" /&gt; &lt;label for="branch_office_city_2"&gt;City&lt;/label&gt; &lt;input class="req" type="text" name="branch_office_city_2" id="branch_office_city_2" /&gt; &lt;label for="branch_office_state_2"&gt;State&lt;/label&gt; &lt;select id="branch_office_state_2" name="branch_office_state_2"&gt; &lt;?php echo $formHelper-&gt;stateList; ?&gt; &lt;/select&gt; &lt;label for="branch_office_zip_2"&gt;Zip&lt;/label&gt; &lt;input class="req zip" type="text" name="branch_office_zip_2" id="branch_office_zip_2" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="spacer"&gt;&lt;/div&gt; &lt;small class="red"&gt;If more than one branch office, please&lt;/small&gt;&lt;a class="addMore" title="Add Branch" id="addBranch"&gt;Add More&lt;/a&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload