下拉列表html中的值

时间:2013-04-15 02:14:32

标签: php html

尝试从下拉列表中传递值但无法获取它。

                <tr>
                    <td>Size <br>
                    (Only applicable for T-Shirt):</td>
                    <td><select name=size>
                    <option value=N>NIL</option>
                    <option value=S>S</option>
                    <option value=M>M</option>
                    <option value=L>L</option>
                    <option value=XL>XL</option>
                    </select></td>
                </tr>

                <tr>
                    <td></td>
                    <td><a href= manageProduct.php?size=$_GET[size]>Insert</a></td>
                </tr>

3 个答案:

答案 0 :(得分:1)

尝试一下:( 只是一个例子)。

<form action="<?php $_SERVER['PHP_SELF']?>" method="GET">
<table>
<tr>
<td nowrap>Size:
(Only applicable for T-Shirt):</td>
<td><select name="size">
<option value="N">NIL</option>
<option value="S">S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
</select></td>
</tr>

<tr>
<td><p align="right"></p></td>
<td><input type="submit" value="Insert" />
</td>
</tr>
</table>
</form>

<?php

$size = $_GET['size'];

if($_GET['size']=="N")
{
echo "you chose NOTHING, make another choice.";
}

else {

echo "Your choice of size is: $size";
}

?>

答案 1 :(得分:0)

您需要使用GET操作的表单,然后才能获得变量。 假设此页面是manageProduct.php:

        <!--GET your data from the submitted form OR do something depending on what size returns in the url-->
    <?php

    if($_GET['size']=="SIZE"){ echo whatever or do whatever}
    ?>


        <td><a href

="manageProduct.php?size=<? echo $_GET['size'] ?>">Whatever you're trying to do</a></td>

        <form id="form" method="get" action="manageProduct.php">
            <tr>
                            <td>Size <br>
                            (Only applicable for T-Shirt):</td>
                            <td><select name="size">
                            <option value="N">NIL</option>
                            <option value="S">S</option>
                            <option value="M">M</option>
                            <option value="L">L</option>
                            <option value="XL">XL</option>
                            </select></td>
                        </tr>

                            <tr>
                                <td></td>
    <td><input type="submit" name="Submit" value="Insert" /></td>
    <br />
    </form>

                            </tr>

答案 2 :(得分:0)

<强> HTML

<form action="manageProduct.php" method="POST">
    <table>
       <tr>
            <td>Size <br>
            (Only applicable for T-Shirt):</td>
            <td><select name=size>
            <option value=N>NIL</option>
            <option value=S>S</option>
            <option value=M>M</option>
            <option value=L>L</option>
            <option value=XL>XL</option>
            </select></td>
        </tr>

        <tr>
            <td></td>
            <td><input type="submit" value="Insert" /></td>
        </tr>
    </table>
</form>

<强> PHP

$size = $_POST['size'];