Real Time Example add dynamic fields using jquery looking Treeview

I have Implemented add Dynamic Fields Using jquery

Look at code :

  1. <html>
  2. <head>
  3. <title>Dynamically add input field using jquery</title>
  4. <style>
  5. .container1 input[type=text] {
  6. padding:5px 0px;
  7. margin:5px 5px 5px 0px;
  8. }


  9. .add_form_field
  10. {
  11.     background-color: #1c97f3;
  12.     border: none;
  13.     color: white;
  14.     padding: 8px 32px;
  15.     text-align: center;
  16.     text-decoration: none;
  17.     display: inline-block;
  18.     font-size: 16px;
  19.     margin: 4px 2px;
  20.     cursor: pointer;
  21. border:1px solid #186dad;

  22. }

  23. input{
  24.     border: 1px solid #1c97f3;
  25.     width: 260px;
  26.     height: 40px;
  27. margin-bottom:14px;
  28. }

  29. .delete{
  30.     background-color: #fd1200;
  31.     border: none;
  32.     color: white;
  33.     padding: 5px 15px;
  34.     text-align: center;
  35.     text-decoration: none;
  36.     display: inline-block;
  37.     font-size: 14px;
  38.     margin: 4px 2px;
  39.     cursor: pointer;

  40. }
  41. </style>
  42. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  43. <script>
  44. $(document).ready(function() {
  45.     var max_fields      = 20;
  46.     var wrapper         = $(".container1"); 
  47.     var add_button      = $(".add_form_field"); 
  48.     
  49.     var x = 0; 
  50.     $(add_button).click(function(e){ 
  51.         e.preventDefault();
  52.         if(x < max_fields){ 
  53.             x++; 
  54.             $(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
  55.         }
  56. else
  57. {
  58. alert('You Reached the limits')
  59. }
  60.     });
  61.     
  62.     $(wrapper).on("click",".delete", function(e){ 
  63.         e.preventDefault(); $(this).parent('div').remove(); x--;
  64.     })
  65. });
  66. </script>
  67. </head>
  68. <body>
  69. <div class="container1">
  70.     <button class="add_form_field">Add New Chapters  &nbsp; <span style="font-size:16px; font-weight:bold;">+ </span></button>
  71.     
  72. </div>
  73. </body>
  74. </html>
  75.  

Comments

Popular posts from this blog

CREATING INTERNET APPLICATION PROJECT & MVC USING DATA BASE FIRST APPROACH

How to create DATA BASE And Tables in MSSQL Server

Data Type Conversions in C# with real time example

Nullable Type In C# with Example

Basic -C# Reading and writing to a console