我正在尝试从表单的元素中检索值。但由于某种原因,我只能从一个元素中获取值。
这是我的html代码:
<form name="registerform" class="registerform">
<label for="usernamefield">Username: </label>
<br>
<input type="field" id="usernamefield"></input>
<br>
<label for="emailfield">Email: </label>
<br>
<input type="email" name="emailfield" id="emailfield"></input>
<br>
<label for="passwordfield">Password: </label>
<br>
<input type="password" name="passwordfield" id="passwordfield"></input>
<br>
<label for="passwordrepeatfield">Repeat Password: </label>
<br>
<input type="password" name="passwordrepeatfield"></input>
<br>
<!--Check field-->
<br>
<input type="checkbox" name="agreementbox" id="agreementbox"></input>
<label for="agreementbox" id="termslink">I agree to the </label>
<a href="" id="termslink">terms</a>
<br>
<input type="button" id="registerbutton" value="Register" onclick="registerUser()">
</form>
这是javascript代码:
function registerUser()
{
var username = document.getElementById("usernamefield").value;
var email = document.getElementById("emailfield").value;
var password = document.getElementById("passwordfield").value;
console.log("Username: " + username);
console.log("Email: " + email);
console.log("Password: " + password);
if (window.XMLHttpRequest)
{
// Code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{
// Code for IE6, IE5
xmlhttp = ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST",
"RegisterUser.php?username=" + username
+ "&email=" + email
+ "&password" + password,
true);
xmlhttp.send();
}
在控制台中,我只看到输入到电子邮件字段中的值。
希望可以有人帮帮我。提前致谢 :)