lundi 4 juin 2018

Facing issues with multiple function calls on single click event

Hello there i am trying to toggle links on a checkbox. Can some where here help me to fix this code

$(document).ready(function() {
  
var obj = document.createElement("audio"); 
    obj.setAttribute("src", "http://www.example.com/media/dunfieldClick.mp3");
    this.volume = 0.2;


$("label").click(function() {
  
  obj.play(); 
  $("body, section, section section, section section section, section section section p").toggleClass('on');
                            });
  }); 

function color() {
   var element = document.getElementById("myDIV");
   element.classList.toggle("green");
}

function link() {
        var checkbox = document.querySelector(".text-center p-l-60 p-t-27");
   checkbox.addEventListener( 'change', function() {
    if(this.checked) {
  
           var url = "example.com/led/update.php?id=1&status=on";
                                $.getJSON(url, function(data) {
                                        console.log(data);
                                }
                else {
                        var url = "example.com/led/update.php?id=1&status=off";
                                $.getJSON(url, function(data) {
                                        console.log(data);
                }               
                }       
   }
});
}

function myFunction() {
        color();
        link();
}
<form class="button-form validate-form" id="myDIV">
                                        <span class="button-form-logo">
                                                <img src="images/logo.png" alt="logo"></i>
                                        </span>

                                        <span class="button-form-title p-b-34 p-t-27">
                                                You are login successfully!
                                        </span>


                                        
                                
                                <div class="text-center p-l-60 p-t-27">
                                
  <input type="checkbox" id="myCheck"  onclick="myFunction();">
  <p id="text" style="display:none">LED is ON</p>
  
</div>     
</form>

I am using Multiple Function Calls with One Onclick. But whenever I use the code no script run or checkbox get disabled. what i am trying to do is turn on off LED on checkbox selection.

Can anyone here help me with this code.




Aucun commentaire:

Enregistrer un commentaire