I am trying to make my a dropdown box read-only and no matter what I do, I can't seem to make it read-only.
Non working code.
<?php
if($_SESSION['id'] == $all_information['complain_from']){ ?>
<select name="complain_form" class="custom-select">
<option value="<?php echo $all_information['complain_from']; ?>" readonly><?php echo $_SESSION['real_name']; ?></option>
</select>
<?php }else{ ?>
<select name="complain_form" class="custom-select">
<option value="" disabled selected>Select a name</option>
<?php
foreach($all_account_info as $account_info){ ?>
<option value="<?php echo $account_info['id']; ?>" <?php if($all_information['complain_from'] == $account_info['id']){ echo 'selected="selected"'; } ?> readonly>
<?php
echo $account_info['real_name'];
?>
</option>
</select>
CodePudding user response:
If you only want to show a selected value in a <select>
element you can set the disabled
attribute for that <select>
:
<select name="complain_form" class="custom-select" disabled>
<option value="<?php echo $all_information['complain_from']; ?>"><?php echo $_SESSION['real_name']; ?></option>
</select>
This will grey out the <select>
and nothing will happen when clicking it