Reputation: 5
I have a very simple page where a user just need to choose one or two options and that automatically fills the rest of form. The form requires the user that enters the data to fill in a username and password.
So I've used this on other parts of the web and it works but for the password field it does not fill it, and when I press send on the form it fails sallyin no passowrd was filled.
<select id="username" name="username" onChange="getpass(this.value)">
....
....
<input id="pwd" size="10" type="password" name="password" value="">
The javascript that is invoqued on the change is:
function getpass(str) {
var xhttp;
if (str.length == 0) {
document.getElementById("pwd").innerHTML = "";
return;
}
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("pwd").innerHTML = this.responseText;
}
};
xhttp.open("GET", "getpass.php?q="+str, true);
xhttp.send();
}
If I change the field to a select list the string used as password appears as an option correctly. But the Submit form fails since it is expecting a password type.
The idea is to avoid users having to enter their password twice, since is known value (almost same as username). All security consideration are not relevant in this use case.
Upvotes: 0
Views: 2344
Reputation: 1083
Try this:
document.getElementById("pwd").value = this.responseText;
Upvotes: 1