所以我在弄清楚为什么我的onchange
事件没有触发时遇到了问题。从这里开始是我的表格和我的 JavaScript 的副本
桌子:
<form name="form1" action="submit.php" method='POST'>
<table border="0" class="signUp">
<tr><td align="center" class= "signUpfont"> Sign up for FREE </td></tr>
<tr><td><input type="text" text="First Name" class='signUpinput' id="fname" name="fname" placeholder="First Name" /></td></tr>
<tr><td><input type="text" class='signUpinput' id="lname" name="lname" placeholder="Last Name"/></td></tr>
<tr><td><input type="text" class='signUpinput' id="email" name="email" placeholder="Email"/></td></tr>
<tr><td><input type="text" class='signUpinput' id="email2" name="email2" placeholder="Re-enter Email"/></td></tr>
<tr><td><input type="password" class='signUpinput' id="pass" name="pass" placeholder="Password"/></td></tr>
<tr><td>
<select name="country" onchange="getStates()" style="color: white; background-color: #2B4478;">
<option value="0">Select State</option>
<option value="louisiana">Louisiana</option>
<option value="texas">Texas</option>
<option value="alabama">Alabama</option>
<option value="mississippi">Mississippi</option>
</select></td>
</tr>
<tr>
<td><select name="school" style="color: white;background-color: #2B4478;">
<option value="">Select School</option>
</select></td></tr>
<tr><td><input type="submit" name="submit" value="Sign Up" style="color:white; background-color:#2B4478; width: 100px;margin-left: 52px;"></td></tr>
</table>
Javascript:
<script type="text/javascript">
function getStates()
{
var xmlhttp;
try{
xmlhttp = new XMLHttpRequest;
}catch(e)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlhttp)
{
var form = document['form1'];
var country = form['country'].value;
xmlhttp.open("GET", "getSchools.php?country="+country, true);
xmlhttp.onreadystatechange = function ()
{
if(this.readyState == 4)
{
var s = document.createElement('select');
s.name = "school";
s.style.color = "white";
s.style.background = "#2b4478";
s.innerHTML = this.responseText;
if(form['school'])
{
form.replaceChild(s, form['school']);
}else
form.insertBefore(s, form['submit']);
}
}
xmlhttp.send(null)
}
}
任何指向我做错的事情的指针将不胜感激。如果我将两个下拉菜单放在同一位置并在其中启动表单,则脚本将起作用,但我无法获取其余的表信息。