-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
78 lines (64 loc) · 1.79 KB
/
index.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html>
<head>
<title></title>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
</head>
<body>
<form method="post">
<div class='input-form'>
<label>School</label>
<div class="school">
<input type='button' class='btnAdd' value='Add new'>
<div class="append_school">
<input type='text' placeholder='Enter name' name='school[]' id='POST_name' class='txt' >
</div>
</div>
<label>High School</label>
<div class="high_school">
<input type='button' class='btnAdd' value='Add new'>
<div class="append_high_school">
<input type='text' placeholder='Enter name' name='high_school[]' id='POST_name' class='txt' >
</div>
</div>
</div>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])) {
var_dump($_POST);
}
?>
<script type="text/javascript">
$(document).ready(function(){
$('.btnAdd').click(function(){
var me = $(this), className = me.parent().prop('className');
var counter = $('.'+ className +' .txt').length,
limit = 3;
//debugger;
console.log(counter);
counter++;
if(counter <= limit) {
var school_html = "<div class='clone'><input type='text' placeholder='Enter name' name='school[]' id='POST_name' class='txt' ><button type='button' class='remove'>x</button></div>";
var high_school_html = "<div class='clone'><input type='text' placeholder='Enter name' name='high_school[]' id='POST_name' class='txt' ><button type='button' class='remove'>x</button></div>";
if(className == 'school') {
html = school_html;
}else if(className == 'high_school'){
html = high_school_html;
}else{
html = "";
}
$('.append_'+className).append(html);
}
});
$('body').on('click','.remove',function(e) {
var me = $(this);
me.parent('.clone').remove();
});
});
</script>