将按钮的ID传递给另一页

时间:2014-12-19 15:49:29

标签: php

以下是我的HTML。我想在点击按钮时将下拉列表(d1和d2)的名称传递给另一个survey.php页面。

<!DOCTYPE html>
<head>
<title>Survey</title>
</head>
<body>
 <form id="form1" action="survey.php" method="POST">
<table border=1>
<tr>
    <td height=" 30" width="200">
    Condition of the item received:
    <select name="d1">
        <option>Select One</option>
        <option value="g">Good</option>
        <option value="s">bad</option>
        <option value="u">Worst</option>
    </select>
    </td>
    <td height=" 30" width="200">
        Price of the Item:
    <select name="d2">
        <option>Select One</option>
        <option value="g">Good</option>
        <option value="s">bad</option>
        <option value="u">Worst</option>
    </select>
    </td>
</tr>
<tr>
    <td align="center" >
        <input type="button" name="submit1"  value="Submit" />
    </td>
</tr>
</table>
</form>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

重写:

        <form id="form1" action="survey.php" method="POST">
        <table border=1>
        <tr>
            <td height=" 30" width="200">
            Condition of the item received:
            <select name="d1">
                <option>Select One</option>
                <option value="Good">Good</option>
                <option value="bad">bad</option>
                <option value="Worst">Worst</option>
            </select>
            </td>

            <td height=" 30" width="200">
                Price of the Item:
            <select name="d2">
                <option>Select One</option>
                <option value="Good">Good</option>
                <option value="bad">bad</option>
                <option value="Worst">Worst</option>
            </select>
            </td>
        </tr>
        <tr>
            <td align="center" >
                <input type="button" name="submit1"  value="Submit" />
            </td>
        </tr>
        </table>
        </form>

答案 1 :(得分:-1)

首先,而不是:<input type="button" name="submit1" value="Submit" />

使用:<input type="submit" name="submit1" value="Submit" />

<input type="submit">是用于实际发送表单的内容。

其次,在survey.php的主体中:

<?php
echo "You rated ".$_POST['d1']." for condition."
echo "You rated ".$_POST['d2']." for price."
?>

简而言之:

PHP中的$_POST变量自动设置为包含所有POST参数的字典。