Trouble disabling drop option after being selected

Im having trouble disabling options selected from a drop down list with multiple selections.

Below is a section of my code.

<table>
</select>
</label>
</td>
<td>

	&lt;label for="seatsA"&gt;
		&lt;br&gt;
		&lt;label for="seatsA"&gt;

<select SIZE=“27” multiple name=“seatsA”>
<optgroup label=“Row A”>
<option selected=“selected”></option>
<option>A01</option>
<option>A02</option>
<option>A03</option>
<option>A04</option>
<option>A05</option>
<option>A06</option>
<option>A07</option>
<option>A08</option>
<option>A09</option>
<option>A10</option>
<option>A11</option>
<option>A12</option>
<option>A13</option>

I have this linked to a form so that seats can be booked for a certain purpose.
However i want the selected options to be ‘disabled’ upon selecting so the next user booking cannot select the same option.

I tried putting <option value = “A01”<?php if ($sel == ‘A01’) echo ‘disabled’; ?>>A01</option> into the first option however it did not disable the option.

Does anyone know a fix for this?

Assuming your $sel variable contains the value A01, then I see no reason why that shouldn’t work.

Your code would have a lot of repetition though if you put in an IF statement for every option - perhaps you should generate the option list instead? The following should do that:


<select>
<?php
for($i = 1; $i < 14; ++$i) {
	$val = sprintf('A%02d', $i);
	printf('<option value="%s"', $val);
	if($sel === $val)
		echo ' disabled="disabled"';
	printf('>%s</option>', $val);
}
?>
</select>

Perhaps my $sel variable is wrong.
How should it look?

Perform a var_dump($sel); in your script to see what value it contains.

I just placed this in my code, and thank you! it saves a bunch of repetition:)

Also i performed a var_dump($sel) and the variable is undefined. what value should it contain?
-I’m (very) new to PHP so I’m sorry for being a nuisance.

Where is the $sel variable coming from? Could you show us that part of the script?

I have this placed under my <html> tag.

<?php
$sel= “AO1”; “AO2”;
?>

Is that on the same page as the generation code for the select box?

Your ‘A02’ value is not apart of the $sel variable. If you’d like to specify multiple disabled items in your select box, then you’ll need $sel to be an array, and the above script to generate the option list would need to be modified to the following:


<select> 
<?php 
for($i = 1; $i < 14; ++$i) { 
    $val = sprintf('A%02d', $i); 
    printf('<option value="%s"', $val); 
    if(in_array($val, $sel, true)) 
        echo ' disabled="disabled"'; 
    printf('>%s</option>', $val); 
} 
?> 
</select>

Yes it is on the same page as the select box code.

So would i need $sel to equal something like:

$sel= array(“AO1”, “AO2”);

?