javascript - How to set values in dynamically created text boxes -
in app creating dynamic textboxes clicking add button. can put values , time also. need when page loads, want given number of textboxes created , populated set of values. able create text boxes onload cannot set values. here giving fiddle have created functionality. how can set values dynamically? here fiddle myfiddle
and want timepicker function in onload created boxes.
function gettextboxaftervaliddation(val){ var str_array = ['jeet','chatterjee']; var randomid = '\''+"#interviewname"+val+'\''; var nameid = "interviewname"+val+""; var allnames = str_array.replace(/((\[)|(\]))/g,""); alert(randomid) $(randomid).val(arr[val]); return '<input class="txt1" name = "dynamictextbox" type="text" id = "'+nameid+'"/>'; } for(var = 0; < 4; i++){ var div = $("<div />"); div.html(gettextboxaftervaliddation(i)); $("#textboxcontainer").append(div); }
when dynamically generate each element increment counter , use value elements id. can put html or values each element using jquery. in example below every time click button id "addphys" append new div on. later can grab values each div because know count , each new div id phys1, phys2, phys3...
var numphys = 0; $("#addphys").click(function(){ $("#test").append("<div class=\"addedphys\"><p id=\"phys"+ numphys + "\"><p><label>physician username:</label><input type=\"text\" class=\"inputbox\" id=\"physusername" + numphys + "\" name=\"pass\"></p><p><label>physician password:</label><input type=\"text\" class=\"inputbox\" id=\"physpassword" + numphys + "\" name=\"pass\"></p></p></div>"); numphys += 1; });
hope helps.
Comments
Post a Comment