Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to get ID and checkbox status ( I have CSS as a Button)

Button name and if active

HTML
<div class="onoffswitch">
    <input type="checkbox" data-bind="checked: ioValue" class="onoffswitch-checkbox" id="io1">
        <label class="onoffswitch-label" for="io1">
        <span class="onoffswitch-inner"></span>
        <span class="onoffswitch-switch"></span>
    </label>
</div>
<div class="onoffswitch">
    <input type="checkbox" data-bind="checked: ioValue" class="onoffswitch-checkbox" id="io3">
        <label class="onoffswitch-label" for="io3">
        <span class="onoffswitch-inner"></span>
        <span class="onoffswitch-switch"></span>
    </label>
</div>


The button works and show true false, I can not work out how to get the ID

JavaScript
self.ioEvent = function(data, event) {
            console.log(1)
            console.log(data)

            console.log(data[0])
            console.log(data[1])

            $.ajax({
                 type: "GET",
                 dataType: "json",
                 data: {"io": data[0], "status": data[1]},
                 url: "/plugin/test/setIOcheckbox",
                 async: false
         });
     }


What I have tried:

I have tried adding code none work yet like ($data, ['io1', 'on']).
Posted
Comments
SrikantSahu 10-Apr-17 5:29am    
This self.ioEvent, how you are binding them? Usually you should have the information about the sender in the event input parameter. I suggest, you log it and check the sender information and then you can prepare the data for the ajax call.
Normally, if the binding is correct $(this) represents the object which triggered the vent and you will get the value of $(this) inside the eventhandler.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900