Please I am a beginner and I'm looking how to dynamically-add / remove textbox jquery.
Thank you.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Munesh SharmaRank #174 · 13.9K reputationPosted Jun 24, 2015, 10:14 PM EDT
Rohan GuptaRank #2,588 · 539 reputationPosted Jun 24, 2015, 10:16 PM EDT
html> head> title>jQuery add / remove textbox example/title> script type="text/javascript" src="jquery-1.3.2.min.js">/script> style type="text/css"> div{ padding:8px; } /style> /head> body> h1>jQuery add / remove textbox example/h1> script type="text/javascript"> $(document).ready(function(){ var counter = 2; $("#addButton").click(function () { if(counter>10){ alert("Only 10 textboxes allow"); return false; } var newTextBoxDiv = $(document.createElement('div')) .attr("id", 'TextBoxDiv' + counter); newTextBoxDiv.after().html('label>Textbox #'+ counter + ' : /label>' + 'input type="text" name="textbox' + counter + '" id="textbox' + counter + '" value="" >'); newTextBoxDiv.appendTo("#TextBoxesGroup"); counter++; }); $("#removeButton").click(function () { if(counter==1){ alert("No more textbox to remove"); return false; } counter--; $("#TextBoxDiv" + counter).remove(); }); $("#getButtonValue").click(function () { var msg = ''; for(i=1; i){ msg += "\n Textbox #" + i + " : " + $('#textbox' + i).val(); } alert(msg); }); }); /script> /head>body> div id='TextBoxesGroup'> div id="TextBoxDiv1"> label>Textbox #1 : /label>input type='textbox' id='textbox1' > /div> /div> input type='button' value='Add Button' id='addButton'> input type='button' value='Remove Button' id='removeButton'> input type='button' value='Get TextBox Value' id='getButtonValue'> /body> /html>Rajeesh MenothRank #118 · 18.4K reputationPosted Jun 24, 2015, 10:18 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 24, 2015, 11:04 PM EDT