lundi 22 mai 2017

Showing and Hiding element using PHP

What I am trying to do is show an element when the button(bar_btn)is clicked. Then, when the button is clicked again, the element's display is set to "none". What happens is that the second if statement is implemented when the button is clicked for the first time. Thank you!

Php:

          $award_bar = 'Next Award';
          $hide_bar = 'none';
        if(isset($_POST['bar_btn'])) {

            $award_bar = 'Hide';
            $hide_bar = 'inline-block';
        }

        if(isset($_POST['bar_btn']) && $award_bar == 'Hide') {

            $award_bar = 'Next Award';
        $hide_bar = 'none';


    }

html:

<form method="post" action="index.php">
  <input type="submit" style="float:right;width:120px;margin-right:40px" 
class="btn btn-success" name="bar_btn" value="<?php echo $award_bar; ?>">
</form>

<div style="display:<?php echo $hide_bar;?>;border:none;width:50%;">
   <p>Some text </p>
</div>

Aucun commentaire:

Enregistrer un commentaire