JQuery keyup on dynamic textboxes on dynamic form -


i have form has button trigger jquery create additional form on same page.

this 2nd form has 2 text boxes: first 1 account, second 1 bankaddress

when bankaddress gets focus, button created add more bankaddress text boxes. works fine , keyup trigger works fine until added code add index end of bankaddress name & id identify each box.

any ideas?

js

function doaddmorebank(form) {	      $('<p class="ptxtfields"><label for="newbankaddress">&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp</label>' +         '<input type="text" value="new switft address" class="newbankaddress inputnumtextbox1 keyup-charnumonly" maxlength="23">' +        '<span class="bankaddrspan errorstyle"><span></p>').insertbefore("#idaddmorebank"); 	       addbanknames(this.form);  }      function addbanknames(form) {		   		      $('.newbankaddress').each(function(i) {          $(this).attr('id', 'newbankaddress' + (i + 1));      	$(this).attr('name', 'newbankaddress' + (i + 1));      });  }  	  // $(document).on('keyup', "[id^=newbankaddress]", function() {   $(document).on('keyup', "#newbankaddress1", function() {       alert=("i editing " );     	  });

this little off topic, don't seem using functions full power.

you're passing form 2 of these functions , not using in either can see. might overlooking it, deff not seeing it. you're using ids when should using form of dynamic selection can reuse these functions without depending on markup, isn't super important right second.

function doaddmorebank(form) {       $('<p class="ptxtfields"><label for="newbankaddress">&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp</label>' +      '<input type="text" value="new switft address" class="newbankaddress inputnumtextbox1 keyup-charnumonly" maxlength="23">' +     '<span class="bankaddrspan errorstyle"><span></p>').insertbefore("#idaddmorebank");          addbanknames(form); } 

this.form isn't targeting anything.... unless show html markup prove doing correctly passing form should efficient enough.

function addbanknames(form) {                $('.newbankaddress').each(function(i) {             $(this).attr('id', 'newbankaddress' + (i + 1));             $(this).attr('name', 'newbankaddress' + (i + 1));         }); } 

here targeting specific id if id doesn't exist ever won't work. instead target class , work bank addresses. without question.

$(document).on('keyup', ".newbankaddress", function() {       alert=("i editing " );   }); 

edit

btw... if you're using server side logic post variables , not there opportunity make script better , more dynamic. rid of pesky $.each()

literally change doaddmorebank function:

function doaddmorebank(form) {       $('<p class="ptxtfields"><label for="newbankaddress">&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp</label>' +      '<input type="text" value="new switft address" name="newbankaddress[]" class="newbankaddress inputnumtextbox1 keyup-charnumonly" maxlength="23">' +     '<span class="bankaddrspan errorstyle"><span></p>').insertbefore("#idaddmorebank");  } 

just adding newbankaddress[] can have many bank addresses want added. in server side loop through each version , deal needed. have decide best way because may necessary 1 of 2 ways.

after doing can drop function addbanknames


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -