JavaScript replace in jQuery html() -
i facing little problem in javascript. have template use add fields form:
<div id="persontemplate" style="display: none;"> <s:url id="personnelist" action="personnelist" namespace="/ajax" /> <sj:autocompleter name="personnescontacts[id_xxx]" id="nompersonne_idxxx" forcevalidoption="false" key="label.servicecontacts" href="%{personnelist}" /> </div>
with jquery, content in persontemplate div, :
<input id="nompersonne_idxxx" name="personnescontacts[1]" type="hidden"> <input autocomplete="off" class="ui-autocomplete-input" name="personnescontacts[id_xxx]_widget" id="nompersonne_idxxx_widget" type="text"> <span class="ui-helper-hidden-accessible" aria-live="polite" role="status"></span> <script type="text/javascript"> jquery(document).ready(function () { var options_nompersonne_idxxx_widget = {}; options_nompersonne_idxxx_widget.hiddenid = "nompersonne_idxxx"; options_nompersonne_idxxx_widget.selectbox = false; options_nompersonne_idxxx_widget.forcevalidoption = false; options_nompersonne_idxxx_widget.jqueryaction = "autocompleter"; options_nompersonne_idxxx_widget.id = "nompersonne_idxxx_widget"; options_nompersonne_idxxx_widget.name = "personnescontacts[id_xxx]_widget"; options_nompersonne_idxxx_widget.href = "/baseline/ajax/personnelist.action"; jquery.struts2_jquery_ui.bind(jquery('#nompersonne_idxxx_widget'),options_nompersonne_idxxx_widget); }); </script>
i tried replace idxxx number, in name attribute occurrence changed. may have idea of how replace idxxx when div content :
<script type="text/javascript"> counter = 0; function addmorepersons() { counter++; var text = $('#persontemplate').html(); text = text.replace("id_xxx", counter); $(text).insertafter($('#personnescontact_0_widget')); }
you need global replace function, if use regular expression, can tell replace all:
text = text.replace(/id_xxx/g, counter);
Comments
Post a Comment