anuj horo
anuj horo

Reputation: 21

i want to hide or show button according to table data

I want to hide or show button according to table data. If data is 0 then button show else hide

<?php

$variable="SELECT * FROM tabel";
$variable1=mysql_query($variable);
$count=1;
$variable2=mysql_fetch_array($variable1)

?>
<?php
$t=$variable2['paid'];
?>
<script>
    var payment_link='<?php echo $t ?>';
    if (payment_link=='0') {
        $('#send').hide();
    }
    else {
        $('#send').show();
    }
</script>
<buttonid="send">SEND</button>

Upvotes: 1

Views: 71

Answers (2)

Jeff
Jeff

Reputation: 6953

The problem is, that the javascript is executed before the button gets even rendered. This is why javascript can't change it yet.

Two possibilities:
Move the <script> part below the <button>

or wrap it in a $( document ).ready(function() { // your code }):

<script>
$(document).ready(function() { 
   var payment_link='<?php echo $t ?>';
    if (payment_link=='0') {
      $('#send').hide();
    }
    else {
        $('#send').show();
    } 
});
</script>

Also make sure to have a space between 'button' and 'id':

<button id="send">SEND</button>

Upvotes: 3

Mohan
Mohan

Reputation: 334

Is the space missing between button and id in the below line?

<buttonid="send">SEND</button>

If that is the case, please change to:

<button id="send">SEND</button>

Upvotes: 1

Related Questions