Reputation: 777
I have this section of code:
<select id="frm_type" name="typeId">
<?php foreach($product_types as $product) : ?>
<?php if ($product['id'] == $product_details['typeId']) $selected = " SELECTED"; else $selected = ""; ?>
<option value="<?=$product['id'];?>"<?=$selected;?>><?=$product['partNumber'];?> (<?=$product['title'];?>)</option>
<?php endforeach; ?>
</select>
This just populates a drop list/option box with data from a DB. This works fine in a form for create where an item is being selected and posted, however I want this same function on an edit page.
The edit page displays the currently selected values, and if unchanged, on post, nothing is posted from this input.
I believed the bits where I have used $selected... in the above, shows the selected option(which it does) it just doesnt send the selected data.
Could anyone offer any suggestions.
Upvotes: 0
Views: 98
Reputation: 54016
try
<select id="frm_type" name="typeId">
<?php foreach($product_types as $product) :
$selected = ($product['id'] === $product_details['typeId'])
? "selected='selected'"
: "";
?>
<option value="<?=$product['id']?>" <?=$selected?> >
<?=$product['partNumber']?> (<?=$product['title']?>)
</option>
<?php endforeach; ?>
</select>
Upvotes: 1
Reputation: 2277
Try
<select id="frm_type" name="typeId" disabled="disabled">
<?php foreach($product_types as $product) : ?>
<?php if ($product['id'] == $product_details['typeId']) $selected = " selected='selected'"; else $selected = ""; ?>
<option value="<?=$product['id'];?>"<?=$selected;?>><?=$product['partNumber'];?> (<?=$product['title'];?>)</option>
<?php endforeach; ?>
</select>
Upvotes: 0