Click here to Skip to main content
14,364,290 members
Rate this:
Please Sign up or sign in to vote.
Hi Team

How do i change my button to true when it reads value as being 1? How i change my button to false if the value is 0 in javascript and its status message each?

What I have tried:

body>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"><br/>
  <div class ="success"></div>
  <div class = "warning"></div>
<div class="col-md-2 text-center"> 
<button id="singlebutton" name="singlebutton" class="btn btn-primary" 

  onclick="BtnOff();">Off</button> <br>
 </div>
  <!------
  ---->
  <br/>
<div class = "col-md-2 text-center">
  <button id = "singlebtn" name="singlebtn" class="btn btn-primary" 

  onclick = "BtnOn();">On</button> <br>
</div>
</body>




function BtnOff() {
    $.ajax({
      url:'https://api.thingspeak.com/update?api_key=D**&field8=0',
      type:'GET',
      data:{
      type:'text'
      },
      success:function(response){
        alert(response);
        $('div.warning').html('status changed').delay(1000).fadeOut();
        $('#singlebutton').append(data);
         }
    
    });
    //setTimeout("Subscribe()", 100);
  
    }
  // second button to unsubscribe.
  function BtnOn() {
    $.ajax({
      url:'https://api.thingspeak.com/update?api_key=D**&field8=1',
      type:'GET',
      data:{
      type:'text'
      },
      success:function(response){
        alert(response);
        $('div.success').html('status changed').delay(1000).fadeOut();
        $('#singlebtn').append(data);
         }
    
      });
    //setTimeout("UnSubscribe()", 100);
  }
Posted
Updated 6-Nov-19 23:41pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Not sure what you mean by "Set button to true". That's not a thing.

If you mean "Show my button or hide it"?
Display property · Bootstrap[^]

if you mean "Disable my button then there is some info down this page:
Buttons · Bootstrap[^]

If not, then please specify what you mean
   
Comments
gcogco10 7-Nov-19 4:44am
   
What i mean here is, if my button is on when click, the status message should change to true. If my button is off when clicked, the status message should change to false and must inform the user for both status message. Why i need some logic there, based on what i have tried. Hope this is clear to all. thanks.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100