Hi Guys. I'm having a serious problem that is holding me back. I have a file which is a user dashboard and this file gets data from another php script file which is called by a user login screen when a user clicks login. The file verify the credentials then if correct that its start to pull some data from the database. The problem is that now there are some users who don't complete their registration process which some stop where they need to make their payments so their accounts are kept with a status of pending which indicate that the user has not pay the registration fee. Now I am able to read the status from the database and assign it to the session so that I will work with on the dashboard, this controls which tells if the complete your registration button should be shown or not of which in this case because the status is pending the dashboard should show this button. My problem is showing or hiding it as this should be hidden when a user has paid his/her registration fee because this update the database with Active status.

I've tried this:

<div if($_SESSION['iiio'] == "pending"){echo " style='display: block';"};><a href="https://www.paymentgateway.com" ><button align="right" id="completeReg" name="completeReg" class="btn btn-danger my-cart-btn my-cart-b" >Complete RegistrationComplete Registration</button></a></div>

But the above will just do what the display:xxxx has if it has none it won't display the block even if the condition is not met for this where it should display because the condition is no met and if I had block it will keep displaying the even if the condition is not met. I've also tried adding the else but still.

I've also tried JavaScript:

`<script type="text/javascript">

 var xadminFee = '<%= Session["iiio"] %>';
 if(xadminFee == "pending"){

     document.getElementById("completeReg").style.display = "block"; // This is for displaying the complete registration process.
 }else{
    document.getElementById("completeReg").style.display = "none";

`}

</script>

And still this seems as if its doesn't work at all because the div will always be shown even if I put nonen but still.

Remember the session is from a php file which contains the exact status from the database.

Anyone who can help me solve this problem.

In first version you are missing the other condition ($_SESSION['iiio'] != "pending"). In that case the div is shown by default.

It looks like you are using Bootstrap so you can use the show and hidden classes provided by Bootstrap. I am using ternary expression here since it is most convenient:

<div class="<?php echo $_SESSION['iiio'] == "pending" ? 'show' : 'hidden';?>"
<a href="https://www.paymentgateway.com">
<button align="right" id="completeReg" name="completeReg" class="btn btn-danger my-cart-btn my-cart-b" >Complete RegistrationComplete Registration</button>
</a>
</div>

If you are not using Bootstrap then create the two classes yourself:

.show {
    display: block;
}

.hidden {
    display: none;
}
commented: Perfect +6

Thank you very much, you are a life saver.

Thanks

Hi broj1,

Can you explain how can I have two conditions that both affect the display of the same div. e.g.

    <div class="<?php echo $_SESSION['iiio'] == "pending" ? 'show' : 'hidden' AND $_SESSION['xmm'] == "standard" ? 'hidden' :'show';?>"
    <a href="https://www.paymentgateway.com">
    <button align="right" id="completeReg" name="completeReg" class="btn btn-danger my-cart-btn my-cart-b" >Complete RegistrationComplete Registration</button>
    </a>
    </div>

I'm sure you can see that I'm trying to show this div is session[iiio] is pending and also hide it if session['xmm'] is a standard member.

A simple and good example is when you have a member and there is an option you want to only display it to certain users, now both the standard user account and lets say profesional user account does meet iiio but now only professional user account can see this. This is just an example to show why I need this kind of condition in this.

Thanks

Got it. Just did it like this:

        <div class="<?php echo $_SESSION['iiio'] == "pending" ? 'show' : 'hidden';?> <?php echo $_SESSION['xmm'] == "standard" ? 'hidden' :'show';?>"
        <a href="https://www.paymentgateway.com">
        <button align="right" id="completeReg" name="completeReg" class="btn btn-danger my-cart-btn my-cart-b" >Complete RegistrationComplete Registration</button>
        </a>
        </div>

Hi,

I would like to answer question display and hide div based on if statement you can use following code

This is the complete soln for future users

 @if (Model.als == -1)

{
    <div style="float: left; width: 80px; visibility:hidden">S139a:</div>
}
     @if (Model.als == 0)
{
     <div style="float: left; width: 80px;">S139a:</div>
     <div style="float: left;">@Html.Raw("No")</div>

}
      @if (Model.als == 1)
{
      <div style="float: left; width: 80px;">S139a:</div>
      <div style="float: left;">@Html.Raw("Yes")</div>

}

Regards,
Daniel,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.