jquery - Generate element live and put his content in a new live generated element -
i have 2 forms both have auto increments rows. when click on add button far code working fine per need. want post value 1 row other incremented in other table. @ same time have javascript code code not seems work in autoincrement function. here jquery:
<script type='text/javascript'> //<![cdata[ $(document).ready(function() { var currentitem = 7; $('#addnew').click(function() { currentitem++; $('#items').val(currentitem); $('#items2').val(currentitem); var strtoadd = '<tr><td align="center"><input type="text" size="6" maxlength="6" id="ord_' + currentitem + '" maxlength="6" name="ord_' + currentitem + '" class="form-input-oth" onkeyup=$("#ordby_'+ currentitem +'").val($("#ordby_'+ currentitem +'").val())/></td>\n\ <td align="center"><input type="text" size="6" maxlength="6" id="srno' + currentitem + '" maxlength="6" name="srno_' + currentitem + '" class="form-input-oth" onkeyup="document.getelementbyid("srno_' + currentitem + '").value = this.value;"/></td>\n\ <td align="center"><textarea name="descrip_' + currentitem + '" id="descrip_' + currentitem + '" cols="70" class="form-input-textarea" onkeyup="document.getelementbyid("descrip_' + currentitem + '").value = this.value;"></textarea></td>\n\ <td align="center"><input type="text" size="6" maxlength="9" id="unit_' + currentitem + '" maxlength="6" name="unit_' + currentitem + '" class="form-input-rate" onkeyup="document.getelementbyid("unit_' + currentitem + '").value = this.value;"/></td>\n\ <td align="center"><input type="text" size="6" maxlength="9" id="rate_' + currentitem + '" maxlength="6" name="rate_' + currentitem + '" class="form-input-rate" onkeyup="document.getelementbyid("rate_' + currentitem + '").value = this.value;"/></td></tr>'; var strtoadd3 = '<tr><td align="center"><input type="text" size="6" maxlength="6" id="ord_' + currentitem + '" maxlength="6" name="ord_' + currentitem + '" class="form-input-oth" /></td>\n\ <td align="center"><input type="text" size="6" maxlength="6" id="srno_' + currentitem + '" maxlength="6" name="srno_' + currentitem + '" class="form-input-oth" /></td>\n\ <td align="center"><textarea name="text_' + currentitem + '" id="descrip_' + currentitem + '" cols="70" style="display: none;"></textarea></td>\n\ <td align="center"><input type="text" size="6" maxlength="9" id="unit_' + currentitem + '" maxlength="6" name="unit_' + currentitem + '" class="form-input-rate" /></td>\n\ <td align="center"><input type="text" size="6" maxlength="9" id="rate_' + currentitem + '" maxlength="6" name="rate_' + currentitem + '" class="form-input-rate" /></td></tr>'; $('#data').append(strtoadd); $('#data3').append(strtoadd3); }); }); //]]> </script>
you try remove this...
onkeyup=$("#ordby_'+ currentitem +'").val($("#ordby_'+ currentitem +'").val())
...and add event
$( '.class-name-for-input-element-you-want-to-attach-event-to' ).on( 'keyup', function() { var itemidx = parseint( this.id.substr( 4 ), 10 ); // strips 'ord_' id // whatever need integer // find element in #data3 , replace value value in element triggered event $( '#data3' ).find( 'selector' ).val( this.value ); });
in order work, you'll need add class name each of input elements.
simpler version
or if want copy input elements value #data3 tables corresponding input elements, use this:
$( '#data' ).on( 'keyup', 'input, textarea', function() { $( '#data3' ).find( '#' + this.id ).val( this.value ); });
notes
can attach events element exists in dom, can't directly attach event input or textarea element. instead can attach event #data
that, assume, in dom.
without duplicated ids (ids removed #data3 table's input elements)
$( '#data' ).on( 'keyup', 'input, textarea', function() { $( '#data3' ).find( '[name="' + this.id + '"]' ).val( this.value ); });
Comments
Post a Comment