Mercurial > hg > batmud > maputils
changeset 2121:dd280de434b9
Create elements in javascript instead of using direct HTML.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 12 Sep 2019 14:33:29 +0300 |
parents | 1f1f07313eae |
children | 66a54bef0d7e |
files | www/search.js |
diffstat | 1 files changed, 17 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/www/search.js Thu Sep 12 14:32:20 2019 +0300 +++ b/www/search.js Thu Sep 12 14:33:29 2019 +0300 @@ -222,26 +222,30 @@ if (Array.isArray(results) && results.length > 0) { mapList = results; - var str = ""; - // Format results, if any + // Create list of map selection buttons + var mobj = document.getElementById("mapList"); + mapClearChildren(mobj); + for (var i = 0; i < results.length; i++) { var res = results[i]; var id = "map_"+ res[0]; - str += - "<input class=\"map\" id=\""+ id + - "\" type=\"checkbox\" checked=\"checked\">"+ - "<label for=\""+ id +"\">"+ mapCapitalize(res[0]) +"</label>"; - } + + // Checkbox input + var mbut = mapCE("input", id); + mbut.type = "checkbox"; + mbut.checked = true; + mbut.className = "map"; - var elem = document.getElementById("mapList"); - elem.innerHTML = str; + mapAddEventOb(id, mbut, "change", mapUpdateMapCount); + mobj.appendChild(mbut); - for (var i = 0; i < results.length; i++) - { - var res = results[i]; - mapAddEvent("map_" + res[0], "change", mapUpdateMapCount); + // Label for button + var mlabel = mapCE("label"); + mlabel.htmlFor = id; + mlabel.textContent = mapCapitalize(res[0]); + mobj.appendChild(mlabel); } mapUpdateMapCount();