Skip to content
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
Add Remove Input Fields Dynamically Using Jquery

add remove input fields dynamically using jquery

Posted on August 22, 2018September 26, 2021 By XpertPhp

In this article, you can read more about how to add remove input fields dynamically using jquery. if you want to add or remove input fields dynamically then you can see the following example.

sometimes we need to add bulk data. eg. education data. so here we are taking one input box and explaining you through a simple example.

max_fields: The maxField variable is the maximum number of input fields that will be added.
wrapper: The wrapper variable selects the parent element of the input fields.
add_button: The addButton variable will select the add button element.
remove_field: The user click on remove button then will be removed input field.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
if(isset($_POST['btnSubmit'])){
$name = $_POST['name'];
echo "<pre>";
print_r($name);
echo "</pre>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>add remove input fields dynamically using jquery - XpertPhp<title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <script>
$(document).ready(function() {
var max_fields      = 10; //maximum input boxes allowed
var wrapper         = $(".input_fields_wrap"); //Fields wrapper
var add_button      = $(".add_field_button"); //Add button ID
 
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('<div><input type="text" placeholder="Enter Name" name="name[]"/>&nbsp;<a href="#" class="remove_field btn btn-danger btn-sm">Remove</a></div>'); //add input box
}
});
 
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
  </script>
</head>
<body>
<div class="container">
<form class="form-inline" method="post">
<div class="input_fields_wrap">
<div><input type="text" placeholder="Enter Name" name="name[]">&nbsp;<button class="add_field_button btn btn-primary btn-sm">Add More Fields</button></div>
</div>
<button type="submit" name="btnSubmit" class="btn btn-default">Submit</button>
</form>
</div>
</body>
</html>

Please follow and like us:
error
fb-share-icon
Tweet
fb-share-icon

Recommended Posts:

  • how to get current date and time in php
  • Laravel 6 ajax form submit with Jquery validation example
  • How to create Pagination with PHP and MySql
  • Laravel 6 jquery form validation example tutorial
  • How to Convert Date and Time from one timezone to another in php
Jquery, Php Tags:How to Dynamically Add / Remove input fields in PHP, How to Dynamically Add / Remove input fields in PHP Download, How to Dynamically Add input fields, How to Dynamically Add input fields in php, How to Dynamically Remove input fields in PHP

Post navigation

Previous Post: laravel eloquent WhereTime query example
Next Post: Add Remove Input Fields Dynamically in PHP with Jquery Ajax

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tricks jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch Laravel Socialite laravel social login nodejs pagination payment gateway php with mysql react js tutorial rewrite rule send mail validation wysiwyg editor

Latest Posts

  • How to Convert Date and Time from one timezone to another in php
  • how to get current date and time in php
  • Drag and Drop Reorder Items with jQuery, PHP & MySQL
  • Laravel 9 Toastr Notifications Example Tutorial
  • Laravel 9 CRUD Operation Example Using Google Firebase
  • Laravel 9 CKeditor Image Upload With Example
  • Laravel 9 Summernote Image Upload With Example
  • Laravel 9 Stripe Payment Gateway Integrate Example
  • How To Send Email Using Mailtrap In Laravel 9
  • Laravel 9 Fullcalendar Ajax Example Tutorial

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Age Calculator Online
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Copyright © 2018 - 2022,

All Rights Reserved Powered by XpertPhp.com