Javascript jquery AutoComplate İnput not Working .I can try but not this. Add package link but AutoComplate İnput not Working. I want only add pack after autocomplete input working. Only this..I think insertCell Hard this.I dont understend this. id =’dap’
JavaScript
x
12
12
1
$(function() {
2
var availableTags = [
3
"arta",
4
"barta",
5
"barta2",
6
];
7
8
9
$("#dap").autocomplete({
10
source: availableTags
11
});
12
});
JavaScript
1
48
48
1
<html>
2
3
<head>
4
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
5
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" />
6
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
7
<title></title>
8
</head>
9
10
<body>
11
<form method="post" action="add.php">
12
<table id="table1">
13
<tr>
14
<br>
15
<td colspan="4"><a onclick="myFunction1()" style=" color: #000; margin-top: 10px"><i></i> Paket Ekle</a> <a onclick="myDeleteFunction1()" style="color: #000; margin-top: 10px"><i ></i> Paket Sil</a></td>
16
17
</tr>
18
<tr>
19
20
<td valign="bottom"><strong>GTIP No.</strong></td>
21
22
</tr>
23
<tr>
24
25
<td><input name="dap" type="text" style="width:90%; margin-top: 15px"></td>
26
<script>
27
var i = 1;
28
29
function myFunction1() {
30
var table = document.getElementById("table1");
31
var row = table.insertRow(-1);
32
var cell1 = row.insertCell(0);
33
34
35
cell1.innerHTML = "<input name='dap" + i + "' id='dap' type='text' style='width:90%;margin-top:15px;' >";
36
37
i++;
38
}
39
40
function myDeleteFunction1() {
41
document.getElementById("table1").deleteRow(-1);
42
}
43
</script>
44
</table>
45
</form>
46
</body>
47
48
</html>
Advertisement
Answer
You can use on
to bind event on dynamically added element
JavaScript
1
14
14
1
$(function() {
2
var availableTags = [
3
"arta",
4
"barta",
5
"barta2",
6
];
7
8
9
$(document).on('keydown.autocomplete', '#dap', function() {
10
$(this).autocomplete({
11
source: availableTags
12
});
13
});
14
});
JavaScript
1
48
48
1
<html>
2
3
<head>
4
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
5
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" />
6
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
7
<title></title>
8
</head>
9
10
<body>
11
<form method="post" action="add.php">
12
<table id="table1">
13
<tr>
14
<br>
15
<td colspan="4"><a onclick="myFunction1()" style=" color: #000; margin-top: 10px"><i></i> Paket Ekle</a> <a onclick="myDeleteFunction1()" style="color: #000; margin-top: 10px"><i ></i> Paket Sil</a></td>
16
17
</tr>
18
<tr>
19
20
<td valign="bottom"><strong>GTIP No.</strong></td>
21
22
</tr>
23
<tr>
24
25
<td><input name="dap" type="text" style="width:90%; margin-top: 15px"></td>
26
<script>
27
var i = 1;
28
29
function myFunction1() {
30
var table = document.getElementById("table1");
31
var row = table.insertRow(-1);
32
var cell1 = row.insertCell(0);
33
34
35
cell1.innerHTML = "<input name='dap" + i + "' id='dap' type='text' style='width:90%;margin-top:15px;' >";
36
37
i++;
38
}
39
40
function myDeleteFunction1() {
41
document.getElementById("table1").deleteRow(-1);
42
}
43
</script>
44
</table>
45
</form>
46
</body>
47
48
</html>