Click here to Skip to main content
12,622,913 members (30,729 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET C#4.0 jQuery
hi
i want to add dynamic controls let us say(one dropdown ,two text boxes )
for that i have a button when user click on button a new row added
with these three controls

how to do this using jquery?
Posted 11-Sep-12 19:12pm
sharmarun1.7K
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

<div style="display:inline">
<input type="button" id="txtPlain" value="Add Plain Text" style="" />
<input type="button" id="txt" value="Add TextBox" style="" />
<input type="button" id="chk" value="Add CheckBox" style="" />
<input type="button" id="rad" value="Add Radio" style="" />
<input type="button" id="btn" value="Add Button" style="" />
</div>
<div id="holder">


and your JQUERY , you can change as per your requirement

$("#txt").click(function(){
var $ctrl = $('<input/>').attr({ type: 'text', name:'text', value:'text'}).addClass("text");
$("#holder").append($ctrl);
});
$("#chk").click(function(){
var $ctrl = $('<input/>').attr({ type: 'checkbox', name:'chk'}).addClass("chk");
$("#holder").append($ctrl);
});
$("#rad").click(function(){
var $ctrl = $('<input/>').attr({ type: 'radio', name:'rad'}).addClass("rad");
$("#holder").append($ctrl);
});
$("#btn").click(function(){
var $ctrl = $('<input/>').attr({ type: 'button', name:'btn',value:'Button'}).addClass("btn");
$("#holder").append($ctrl);
});
$("#txtPlain").click(function(){
var lbl = prompt ("Enter Text","");
$("#holder").append(lbl);
});


if its working , give a special thank to Brij

http://techbrij.com/445/add-dynamic-form-elements-textbox-button-radio-checkbox[^]
  Permalink  
Comments
sharmarun 12-Sep-12 0:50am
   
i have to add dropdown and bind it with database

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 12 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100