Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

HTML
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>




JavaScript
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 22:41pm
v2

1 solution

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
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900