简体   繁体   中英

Show/Hide Select Option Based on the Type of User

I want to show/hide option from a select drop-down for free user & paid user form a php session value.

   <select id="book" name="book" style="display:none" onchange="update_session_value(this.value)">
        <option id = "c1" class="b1" value="A1">A1</option> 
        <option id = "c2" class="b1" value="A2">A2</option> 
        <option id = "c3" class="b2" value="A3">A3</option> 
        <option id = "c4"class="b2" value="A4">A4</option> 
    </select>

If

$_SESSION['mytype']= freeuser;

then hide option c1 & c2 & show c3 & c4 if

$_SESSION['mytype']= paiduser;

then hide c3, c4 & show c1, c2

How can I achieve this?

   <select id="book" name="book" style="display:none" onchange="update_session_value(this.value)">
<?php if ($_SESSION['mytype'] === 'paiduser') { ?>
        <option id = "c1" class="b1" value="A1">A1</option> 
        <option id = "c2" class="b1" value="A2">A2</option> 
<?php } else { ?>
        <option id = "c3" class="b2" value="A3">A3</option> 
        <option id = "c4"class="b2" value="A4">A4</option> 
<?php } ?>
    </select>

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