Reputation: 11
How to Display the selected value when the option is selected in dropdown menu in phtml without using javascript.here is what i have tried so far!.i am trying this one in magento
<form action="<?php echo $this->getUrl('customer/products/simpleproduct') ?>" enctype="multipart/form-data" method="post" id="form-customer-product-new">
<table class="tablepostion">
<tr>
<td>
<select id="sizeoption">
<option value="1">Small</option>
<option value="2">Medium</option>
<option value="3">Large</option>
</select>
<?php
$a = $_POST['sizeoption'];
echo $a;
?>
</td>
</tr>
</table>
Upvotes: 1
Views: 8335
Reputation:
You need to add name of your dropdown.
<select name="mysize" id="sizeoption">
<option value="Small">Small</option>
<option value="Medium">Medium</option>
<option value="Large">Large</option>
</select>
<?php
$a = $_REQUEST['mysize'];
echo $a;
?>
Thanks,
Upvotes: 3
Reputation: 4076
Try this
<?php $a = $_POST['sizeoption']; ?>
<table class="tablepostion">
<tr>
<td>
<select id="sizeoption">
<option <?php echo ($a ==1)?'selected="selected"' : '' ?> value="1">Small</option>
<option <?php echo ($a ==2)?'selected="selected"' : '' ?> value="2">Medium</option>
<option <?php echo ($a ==3)?'selected="selected"' : '' ?> value="3">Large</option>
</select>
</td>
</tr>
</table>
Upvotes: 1