Skip to content
  • Github
  • Facebook
  • twitter
  • 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, 2018December 17, 2022 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.

Read Also:
Add Remove Input Fields Dynamically in PHP with Jquery Ajax

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>
See also  php Login And Registration Example

Php, Jquery 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

Latest Posts

  • Laravel 12 Ajax CRUD Example
  • Laravel 12 CRUD Example Tutorial
  • How to Create Dummy Data in Laravel 11
  • Laravel 11 Yajra Datatables Example
  • Laravel 11 Ajax CRUD Example
  • Laravel 11 CRUD Example Tutorial
  • Angular 15 CRUD Application Example Tutorial
  • Laravel 10 Form Validation Example Tutorial
  • Angular 15 Custom Form Validation Example
  • Laravel 10 Send Email Example Tutorial

Tools

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

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Interview
  • 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 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 social login learn jquery nodejs pagination payment gateway php with mysql react js example react js tutorial send mail validation wysiwyg editor wysiwyg html editor

Copyright © 2018 - 2025,

All Rights Reserved Powered by XpertPhp.com