0

我有一个注册表单,其中包括 2 个下拉列表,其中一个会根据选择第一个下拉列表中的哪个选项而变化。单击按钮提交后,表单中的所有值都已成功传递,下拉列表中的值除外列表。

我的代码:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8" />
<title>Sign Up</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript">
function configureDropDownLists(ddl1,ddl2) {
    var retail = new Array('Books','Computer Accessories','Electronics', 'Fashion','Others');
    var dining = new Array('Asian','Chinese','French','Italian','Japanese','Korean','Western','Others');

    switch (ddl1.value) {
        case 'Retail':
            document.getElementById(ddl2).options.length = 0;
            for (i = 0; i < retail.length; i++) {
                createOption(document.getElementById(ddl2), retail[i], retail[i]);
            }
            break;
        case 'Dining':
            document.getElementById(ddl2).options.length = 0; 
        for (i = 0; i < dining.length; i++) {
            createOption(document.getElementById(ddl2), dining[i], dining[i]);
            }
            break;

            default:
                document.getElementById(ddl2).options.length = 0;
            break;
    }

}

function createOption(ddl, text, value) {
    var opt = document.createElement('option');
    opt.value = value;
    opt.text = text;
    ddl.options.add(opt);
}
</script>
</head>

<body style="background-color:#FFF">
<div id="container_register">
<div id="header_register"></div>
<div id="welcome_register">Register</div>
<div id="box_register">     
  <form id="RegForm" name="RegForm" method="POST" action="Register.php">
    <table width="460" border="0" cellpadding="5" cellspacing="5">
        <tr>
            <td>Username*</td><td><input type="text" name="username" maxlength="30" size="30" required="required" /></td>
        </tr>
        <tr>
            <td>Email*</td><td><input type="text" name="email" maxlength="30" size="30" required="required" /></td>
        </tr>
        <tr>
            <td>Verify Email*</td><td><input type="text" name="vemail" maxlength="50" size="30" required="required" /></td>
        </tr>
        <tr>
            <td>Password*</td><td><input type="password" name="password" maxlength="50" size="30" required="required" /></td>
        </tr>
        <tr>
            <td>Verify Password*</td><td><input type="password" name="vpassword" maxlength="50" size="30" required="required" /></td>
        </tr>
        <tr>
            <td>Business Name*</td><td><input type="text" name="bizname" maxlength="30" size="30" required="required" /></td>
        </tr>
        <tr>
            <td>Verify Business Name*</td><td><input type="text" name="vbizname" maxlength="30" size="30" required="required" /></td>
        </tr>
        <tr>
            <td>Business Type*</td>
            <td>:
            <select name="type" id="ddl" onchange="configureDropDownLists(this,'ddl2')">
            <option value=""></option>
            <option value="Retail">Retail</option>
            <option value="Dining">Dining</option>
            </select>
        </tr>
        <tr>
            <td>Business SubType*</td>
            <td>:
            <select id="ddl2" name="subtype">
            </select>
            </td>
        </tr>
        <tr>
            <td>Info</td><td><textarea name="info" rows="5" cols="24" maxlength="300"></textarea>
        </tr>
        <tr>
        <td colspan="2"><input type="SUBMIT" name="Button" value="Register"></td>
        </tr>
        <tr>
        <td colspan="2"><?PHP if(isset($errormsg)){echo"$errormsg";}?></td>
        </tr>       
        <tr>
        <td colspan="3"><font color="#FF0000"></font></td>              
        </tr>             
    </table>
  </form>      
</div> 

</div>
</body>
</html>

提交表单后,我被定向到我回显 print_r($POST) 的处理页面,我得到

Array ( [username] => uname [email] => email [vemail] => vemail [password] => pw [vpassword] => vpw [bizname] => name [vbizname] => vname [Button] => Register )

问题: 如何传递下拉列表和文本区域中选定值的值?

4

0 回答 0