Skip to content Skip to sidebar Skip to footer

Send Post Request Only If Check Box Is Checked

So I'm trying to make my script only log and send the POST request if the check box is checked... The problem is when I un-check the box. It's still sending the post request. This

Solution 1:

Have you tried this?

const checkbox = document.querySelector('#myCheckBox');

checkbox.addEventListener('change', e => {
    const self = e.target;
    if (self.checked){
        // send
    }
})
const userlist = document.querySelector('#userlist');
new MutationObserver(() => {
userlist.querySelectorAll('.user:not([data-has-checkbox])').forEach((userDiv) => {
const checkbox = userDiv.insertBefore(document.createElement('input'), userDiv.children[0]);
checkbox.type = 'checkbox';
userDiv.dataset.hasCheckbox = true;
});
}).observe(userlist, { childList: true });

userlist.addEventListener('change', (e, { target }) => {
if ( !e.target.checked ) return
if (target.matches('.user > input[type="checkbox"]')) {
const userDiv = target.parentElement;
var nameb = userDiv.id.replace("user_", "");
}

var evtSource = new EventSource("http://myurl.com/_watch//_index?_=1557958948927");

evtSource.onmessage = function(e) {
var obj = JSON.parse(e.data);
var line = JSON.stringify(obj.line)
var size = JSON.stringify(obj.lineWidth)
var color = JSON.stringify(obj.lineColor) // Not needed, but defined 
anyways.
var chat = JSON.stringify(obj.msg)
var original = line
//var mirror = JSON.parse(JSON.stringify(original).replace(/\d+/g, number => 20 + +number))
var list = JSON.parse(JSON.stringify(userList)) //LineLog


//--------------------------



if (obj.ident === nameb) // if ident ='s userDiv's Id value...
{
$.post("/draw.php?ing=_index", {
           l: (line),
           w : parseInt(obj.lineWidth) + 2,
           c: ("ffffff"),
            o: ("100"),
            f: ("1"),
            _: ("false")
})
console.log(nameb) //log the value.
}
});

Post a Comment for "Send Post Request Only If Check Box Is Checked"