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
| <html lang="fr">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
var oAutoCompleteElements = {
addInputEvents:function(newInputs){
var r_newInputs = $(newInputs);
$(newInputs).each(function(i, oInput){
$(oInput).off();
$(oInput).on('keyup',function(){
var occup = $(oInput).val();
if(occup){
$.ajax({
type: "GET",
url: "page_geneoccup.php",
data: {"occup":occup},
dataType: 'json',
success:function(responseData){
var liste_occup=responseData;
$(oInput).autocomplete({
source: liste_occup
});
return;
},
error:function(XMLHttpRequest, textStatus, errorThrow){
console.log("Error: " + XMLHttpRequest.status + errorThrow );
return;
}
});
}
});
});
},
addButtonEvents:function(){
$('#addNewInput').on('click',function(){
oAutoCompleteElements.addNewInput();
});
},
addNewInput:function(){
newInput ='<input type="text" name="occupation[]"/>';
$('#occupationsContainer').append(newInput);
oAutoCompleteElements.addInputEvents($('input[name="occupation[]"]:last'));
},
init:function(){
this.addButtonEvents();
this.addInputEvents($('input[name="occupation[]"]'));
}
};
$(function(){
oAutoCompleteElements.init();
});
</script>
</head>
<body>
<div id="occupationsContainer">
<input name="occupation[]">
<input type="button" id="addNewInput" value="add">
</div>
</body>
</html> |
Partager