Vote count:
0
I'm trying to build an auto-complete form with Javascript, PHP and Mysql.
Here's the constraints :
- No JQuery, pure Javascript
- No xmlHTTPResquest object, just DSL
- No innerHTML, just dom object moves.
The research works fine and are display correctly, but I can't delete them at each new search, they pile up and create a huge pile of divs.
I've tried a while statement with remove child and finally I've tried the function simpel() below, but no luck.
Anyone has an idea to complete that ?
Thanks,
Here's my javascript :
var planetx = document.querySelector('form:nth-of-type(1)');
var results = document.querySelector('article div:nth-of-type(1)');
function displayFile(data) {
results.style.display = data.length ? "block" : "none";
for (var i = 0, c = data.length; i < c; i++) {
div = document.createElement('div');
p = document.createElement('p');
text = document.createTextNode(data[i]);
p.appendChild(text);
div.appendChild(p);
text.className += "res";
p.className += "res";
div.className += "res";
planetx.appendChild(div);
}
}
function simpel() {
h = document.querySelectorAll('.res');
for (var k = 0, c = h.length; k < c; k++) {
h[k].parentNode.removeChild;
}
}
planetx.addEventListener('input', function(e) {
var scriptElement = document.createElement('script');
scriptElement.type = 'text/Javascript';
scriptElement.src = 'php/mysqlfile.php?name=' + e.target.value;
document.body.appendChild(scriptElement);
}, false);
asked 1 min ago
Aucun commentaire:
Enregistrer un commentaire