-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
41 lines (40 loc) · 1.4 KB
/
index.html
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
<html>
<body>
<form method="post" action="index.html" name="family">
Father:<br>
<input type="text" autocomplete="off" name="father"><br>
Mother:<br>
<input type="text" autocomplete="off" name="mother"><br>
<div class="input_fields_wrap">
<div>Child: <br>
<input type="text" autocomplete="off" name="child[]"><br></div>
</div>
<button class="add_field_button">add children</button>
<input type="submit" name="submit">
</form>
<script src="jquery-3.3.1.min.js"></script>
<script type='text/javascript'>
$(document).ready(function () {
var max_fields = 10,
wrapper = $(".input_fields_wrap"),
add_button = $(".add_field_button"),
x = 1; // initial text box count
$(add_button).click(function (e) {
e.preventDefault();
if (x < max_fields) { //max input box allowed
x++; //text box increment
$(wrapper).append('<div>' +
'Child: <br>' +
'<input type="text" autocomplete="off" name="child[]"><br>' +
'<a href="#!" class="remove_field">remove</a></div>');
}
});
$(wrapper).on('click', '.remove_field', function (e) { // user clicks on remove text
e.preventDefault();
$(this).parent('div').remove();
x--;
});
});
</script>
</body>
</html>