Real Time Example add dynamic fields using jquery looking Treeview
I have Implemented add Dynamic Fields Using jquery
Look at code :
Look at code :
- <html>
- <head>
- <title>Dynamically add input field using jquery</title>
- <style>
- .container1 input[type=text] {
- padding:5px 0px;
- margin:5px 5px 5px 0px;
- }
- .add_form_field
- {
- background-color: #1c97f3;
- border: none;
- color: white;
- padding: 8px 32px;
- text-align: center;
- text-decoration: none;
- display: inline-block;
- font-size: 16px;
- margin: 4px 2px;
- cursor: pointer;
- border:1px solid #186dad;
- }
- input{
- border: 1px solid #1c97f3;
- width: 260px;
- height: 40px;
- margin-bottom:14px;
- }
- .delete{
- background-color: #fd1200;
- border: none;
- color: white;
- padding: 5px 15px;
- text-align: center;
- text-decoration: none;
- display: inline-block;
- font-size: 14px;
- margin: 4px 2px;
- cursor: pointer;
- }
- </style>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
- <script>
- $(document).ready(function() {
- var max_fields = 20;
- var wrapper = $(".container1");
- var add_button = $(".add_form_field");
- var x = 0;
- $(add_button).click(function(e){
- e.preventDefault();
- if(x < max_fields){
- x++;
- $(wrapper).append('<li><a href="#" style="margin-left: 10px;" class="w3-button"><span class="glyphicon glyphicon-triangle-right" name="mytext[]"></span>Chapter '+ x+'</a></li>'); //add input box
- }
- else
- {
- alert('You Reached the limits')
- }
- });
- $(wrapper).on("click",".delete", function(e){
- e.preventDefault(); $(this).parent('div').remove(); x--;
- })
- });
- </script>
- </head>
- <body>
- <div class="container1">
- <button class="add_form_field">Add New Chapters <span style="font-size:16px; font-weight:bold;">+ </span></button>
- </div>
- </body>
- </html>

Comments
Post a Comment