asp.net - Dynamically creating multiple textboxes depending on minimum number of characters in previous textbox/ javascript/asp -


hi have webform in need add multiple textboxes dynamically depending on entry in previous textbox.. if 1 character entered in previous textbox should generate new texbox beside without losing focus previous textbox , should allow me enter many characters without limiting.. here code :

    getid = function ()      {         var id = 1;         return function ()          {             id++;         }     }      function createtextbox()      {         var box = document.getelementbyid("divcreatetextbox");         var curr = 'txt' + getid();         var inp = document.createelement('input');          inp.type = 'text';         inp.name = 'textfield';         inp.setattribute("id", curr);         inp.setattribute("minlength",'1');         box.appendchild(inp);         inp.setattribute('onkeyup', 'moveonmin(this)');         inp.focus();      }      function moveonmin(s)      {       if(s.value.length >= parseint(s.getattribute("minlength")))       {           createtextbox();       } 

the problem above code is, allowing me enter 1 character in 1 textbox , shifts focus on new textbox. everytime try enter more 1 character in textbox creates new textboxes each character. solutions ??

try this.

function createtextbox() {     var box = document.getelementbyid("divcreatetextbox");     var curr = 'txt' + getid();     var inp = document.createelement('input');      inp.type = 'text';     inp.name = 'textfield';     inp.setattribute("id", curr);     inp.setattribute("minlength",'1');     box.appendchild(inp);     inp.setattribute('onkeyup', 'moveonmin(this)');     inp.setattribute("textboxadded", "0");     //inp.focus();  }  function moveonmin(s) {     if (s.value.length == parseint(s.getattribute("minlength")) && s.getattribute("textboxadded") == "0")  {         createtextbox();         s.setattribute("textboxadded", "1");         s.focus();     } } 

i have changed code to: 1. remain focus on existing textbox; , 2. let textbox added once every textbox


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -