我已经改变了措辞,可能更清楚我正在努力实现的目标。我假设我需要Javascript才能完成这项工作,我只是不确定如何使用它。想法?
//the user will make a selection from the following dropdown
<div class="form-group col-lg-offset-3">
<h3>
<select id="flavor" name="id">
<option name="flavor">Select FLAVOR</option>
<option name="1">FRUIT PUNCH</option>
<option name="2">GRAPE</option>
<option name="3">WATERMELON</option>
</select>
</h3>
</div>
//based on the user selection, the option name (i.e. 1, 2, 3) must go after cartAction.php?action=addToCart&id=
<a href="cartAction.php?action=addToCart&id=">
<input type="submit" value="Add To Cart" button type="button" class="btn btn-success center-block button-buffer">
</a>
因此,例如,如果用户选择FRUIT PUNCH,那么href部分将如下所示:
<a href="cartAction.php?action=addToCart&id=1">
<input type="submit" value="Add To Cart" button type="button" class="btn btn-success center-block button-buffer">
</a>
答案 0 :(得分:1)
您必须提供名称选择<select id="flavor" name="selectItem">
<select id="flavor" name="selectItem">
<option name="flavor">Select FLAVOR</option>
<option name="0">FRUIT PUNCH</option>
<option name="1">GRAPE</option>
<option name="2">WATERMELON</option>
</select>
因此您可以将选项值传递给其他页面
然后您可以使用GET
或POST
方法
$item=$_GET['selectItem'];
更新了
<form action="cartAction.php?action=addToCart&id=<?php echo $row["id"]; ?>">
<select id="flavor" name="selectItem">
<option name="flavor">Select FLAVOR</option>
<option name="0">FRUIT PUNCH</option>
<option name="1">GRAPE</option>
<option name="2">WATERMELON</option>
</select>
<input type="submit" value="Add To Cart" button type="button" class="btn btn-success center-block button-buffer">
</form>