0

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.

4
  • Can you use jQuery? Commented Jun 13, 2017 at 8:29
  • Wow. Abort this way of thinking. ALWAYS be secure with passwords, don't set precedence. NEVER STORE PASSWORDS PLAINTEXT. Commented Jun 13, 2017 at 8:34
  • Also, just instruct them to click 'store password' when the browser prompts for it, you'll have a much more secure solution. Commented Jun 13, 2017 at 8:35
  • I know I knooooow. It hurts me too. But the password field is not really a password. Just another string that is stored, then converted to barcode and printed to be laser scanned. They go from one side of the wharehouse to another in this way. I have to use the password field because the barcode generating app and scanner takes the values from the DB password field. Is turtles all the way down. Commented Jun 13, 2017 at 8:54

1 Answer 1

1

Try this:

document.getElementById("pwd").value = this.responseText;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.