qwikad.com
09-07-2015, 01:29 PM
I have this script and I'd really like to show the results as an HTML output. Not sure how to do this myself. I know it can be done with innerHTML. Or maybe there's a better way. Hope you can help. As long as the script can read tags. Thanks!!
(function(d) {
function nodeFlush(e) {
while (e.firstChild) e.removeChild(e.firstChild);
}
function nodeAdd(e, node) {
e.appendChild(typeof node == 'object' ? node : d.createTextNode(node));
}
function nodeReplace(e, node) {
nodeFlush(e);
nodeAdd(e, node);
}
function eventAdd(e, eventName, handler) {
if (e.addEventListener) e.addEventListener(eventName, handler, false);
else e.attachEvent('on' + eventName, handler);
}
var
target = d.getElementById('selections'),
output = d.getElementById('selectionsResults'),
inputs = target.getElementsByTagName('input');
function checkInputs() {
var result = [];
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].checked) result.push(inputs[i].value);
}
nodeReplace(output, result.length ? result.join('<br>') : '0');
}
for (var i = 0; i < inputs.length; i++) {
eventAdd(inputs[i], 'change', checkInputs);
eventAdd(inputs[i], 'click', checkInputs);
}
checkInputs();
})(document);
This is the script if you want to see what it currently does: http://jsfiddle.net/T5Pm7/180/
(function(d) {
function nodeFlush(e) {
while (e.firstChild) e.removeChild(e.firstChild);
}
function nodeAdd(e, node) {
e.appendChild(typeof node == 'object' ? node : d.createTextNode(node));
}
function nodeReplace(e, node) {
nodeFlush(e);
nodeAdd(e, node);
}
function eventAdd(e, eventName, handler) {
if (e.addEventListener) e.addEventListener(eventName, handler, false);
else e.attachEvent('on' + eventName, handler);
}
var
target = d.getElementById('selections'),
output = d.getElementById('selectionsResults'),
inputs = target.getElementsByTagName('input');
function checkInputs() {
var result = [];
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].checked) result.push(inputs[i].value);
}
nodeReplace(output, result.length ? result.join('<br>') : '0');
}
for (var i = 0; i < inputs.length; i++) {
eventAdd(inputs[i], 'change', checkInputs);
eventAdd(inputs[i], 'click', checkInputs);
}
checkInputs();
})(document);
This is the script if you want to see what it currently does: http://jsfiddle.net/T5Pm7/180/