简体   繁体   中英

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>

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM