I'm trying to get data from checkbox alert in Node-red. Inside the template node,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>test</title>
<script>
window.onload = function(){
for(var i = 0; i < document.getElementsByTagName('input').length; i++){
if(document.getElementsByTagName('input')[i].getAttribute('type') == 'checkbox'){
document.getElementsByTagName('input')[i].checked = true;
}
}
};
</script>
</head>
<body>
<label>test<input type="checkbox" name="test1" onclick="send({payload: 1})" /></label>
<label>test<input type="checkbox" /></label>
<label>test<input type="checkbox" /></label>
<label>test<input type="checkbox" /></label>
</body>
</html>
This is my Code in template node. If i inject the node, notification appears.
Even i press Ok/Cancel, nothing happened.The only payload that i can see is
this one which i first inject node, raw template code appears.
What i want to do is, I want individual output among those checkboxes.
For example, if i check 'test1', I wanna make msg.payload="test1" or any number, string etc.
If i check 'test2', 'test3' , 'test4' same. Anyone knows about this? Tnx for reading.
[ { "id": "6a445b83eb98086b", "type": "tab", "label": "플로우 2", "disabled": false, "info": "", "env": [] }, { "id": "a1bcbf893316b76a", "type": "ui_toast", "z": "6a445b83eb98086b", "position": "dialog", "displayTime": "3", "highlight": "", "sendall": true, "outputs": 1, "ok": "OK", "cancel": "Cancel", "raw": true, "className": "", "topic": "", "name": "", "x": 450, "y": 120, "wires": [ [] ] }, { "id": "57461552ebe0a887", "type": "inject", "z": "6a445b83eb98086b", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 120, "y": 120, "wires": [ [ "04f1b9d83919a0f3" ] ] }, { "id": "04f1b9d83919a0f3", "type": "template", "z": "6a445b83eb98086b", "name": "", "field": "payload", "fieldType": "msg", "format": "html", "syntax": "mustache", "template": "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"utf-8\" />\n<title>test</title>\n<script>\nwindow.onload = function(){\n for(var i = 0; i < document.getElementsByTagName('input').length; i++){\n if(document.getElementsByTagName('input')[i].getAttribute('type') == 'checkbox'){\n document.getElementsByTagName('input')[i].checked = true;\n }\n }\n};\n\nfunction handle(){ \n node.send(\"{'name':'\"+e.target.name+\"'}\");\n }\n \n</script>\n</head>\n<body>\n <label>test<input type=\"checkbox\" name=\"test1\" onclick=\"send({payload: 1})\" /></label>\n <label>test<input type=\"checkbox\" /></label>\n <label>test<input type=\"checkbox\" /></label>\n <label>test<input type=\"checkbox\" /></label>\n</body>\n</html>", "output": "str", "x": 270, "y": 120, "wires": [ [ "39ccd676b253dd83", "a1bcbf893316b76a" ] ] }, { "id": "39ccd676b253dd83", "type": "debug", "z": "6a445b83eb98086b", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 450, "y": 180, "wires": [] } ]
Regards.