-1

I have a dynamic drop down menu which is hooked up to a query_string to send to the next screen, how can I validate the information from the drop down menu before it gets sent to the next page? I just don't know how to indentify the dynamic drop down. Thanks again!! This is through the server also. here is the code I have so far.

<tr><td id="giftCardSelectTd">Choose a Gift Card</td></tr><tr><td id="two"> <select name="productId" id="input1">
    <option value="0">Select Card</option><? while($rows=mysql_fetch_array($result)) {$productId=$rows['productId'];$productPrice=$rows['price'];if($productId == '0'){
    $error="Please select a Gift Card."; header('Location: convenientgiftcardpage.php');}if($productPrice < 0){
    $anchor='<td><a id="addtocartbtn" href="convenientcartpage.php?add='. $productId . '">Add to Cart</a></td>';
}
else{
    $anchor='<td><a id="addtocartbtn" href="convenientcartpage.php?add='. $productId . '">Add to Cart</a></td>';
}

    ?>
    <option value="<?php echo $productId;?>">$<?=number_format($productPrice,2);?></option>
    <? } ?></select></td><?php echo $anchor;?>

    </tr>
4

2 回答 2

0

感谢您的帮助,但我想通了!当我使用 GET 方法将代码放入表单时,我可以将下拉列表值发送到购物车,并使用在代码的购物车页面上设置的 Select name""。再次感谢你的帮助。PS我试图将代码放在问题的原始帖子中,但没有成功

于 2012-06-17T16:07:06.217 回答
0
<form name="myform" method="POST" action="" >

<select name="productId" id="input1"> 
<option value="Select Card">Select Card</option>

<?php while($rows=mysql_fetch_array($result)) {
   $productId=$rows['productId'];$productPrice=$rows['price'];
   if ($productPrice < 0) { 
      $anchor='<td><a id="addtocartbtn" href="convenientcartpage.php?add='. $productId . '">Add to Cart</a></td>'; } 
   else {
      $anchor='<td><a id="addtocartbtn" href="convenientcartpage.php?add='. $productId . '">Add to Cart</a></td>';
   }
?> 

<option value="<?php echo $productId;?>">$<?=number_format($productPrice,2);?>
</option> <?php } ?>
</select></td>

<input type="submit" value="Continue" class="btn"/>

<?//php echo $anchor;?>
</form>

<?php
   if((strcmp($_SERVER['REQUEST_METHOD'],'POST')==0) {
      $products = $_POST["productId"] ;
      // validate it
      if (everything is fine) {
         header("location:".$anchor)
      }
   }
?>

希望这可以帮助

于 2012-06-15T19:17:33.340 回答