javascript add input
<script>
$(document).ready(function() {
var max_fields = 10;
var wrapper = $(".container1");
var add_button = $(".add_form_field");
var x = 1;
$(add_button).click(function(e) {
e.preventDefault();
if (x < max_fields) {
x++;
$(wrapper).append('<div><input type="text" name="mytext[]"/><a href="#" class="delete">Delete</a></div>'); //add input box
} else {
alert('You Reached the limits')
}
});
$(wrapper).on("click", ".delete", function(e) {
e.preventDefault();
$(this).parent('div').remove();
x--;
})
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container1">
<button class="add_form_field">Add New Field
<span style="font-size:16px; font-weight:bold;">+ </span>
</button>
<div><input type="text" name="mytext[]"></div>
</div>
Also in JavaScript:
- useful javascript code snippet for console
- missing expression after unary operator '--'
- react function called last state
- js map function
- javascript oneline function
- render blaze in react
- function inside function javascript
- jquery set visibility
- adding growl delete notifications in vanilla js
- generate random number javascript
- replace multiple spaces with single space javascript
- how to add object to array javascript
- javascript string ends with
- javascript button
- node stdin read char by char
- usestate() react
- import all from javascript
- jquery scrollHeight
- React Components
- hackerrank fizzbuzz javascript
- nestjs controller
- from json timestamp to date python
- append div to another div jquery
- user account in react