Jump to content

Setting HTML FORM Field - Not Working


MeOnTheWeb

Recommended Posts

Hi,

So I have a form with various fields.

One is a CHECKBOX - if the user wants the app to generate a password, they check this.

Then I have a password field where the input type is password.

On the checkbox, I have ONCLICK to execute a piece of javascript called generatepassword.

Inside that code, I call a PHP function to create the password.

function generatePassword() 
{
    // Get the checkbox
      var checkBox = document.getElementById("generateuserpassword");

      // Get the output text
      var passvalue = document.getElementById("setuserpassword");

      // If the checkbox is checked, display the output text
      if (checkBox.checked == true)
      {
            // Generated password. User may or may not have accepted this
            passvalue.value = '<?php echo genPassword(15); ?>';
            passvalue.disabled = true;
      } 
}

 

When I view the source I do see this:

// Generated password. User may or may not have accepted this

passvalue.value = 'S<?#{FrZ[COB7AG';

passvalue.disabled = true;

and I use some code to get the post variables

$userpassword = htmlspecialchars($_POST['setuserpassword']);

When I print out $userpassword it is always BLANK. I can't figure out what I'm doing wrong.

I have confirmed the input type, id and name.

 

Link to comment
Share on other sites

Quote

passvalue.disabled = true;

If you disable a form field, then it will not be sent when the form is submitted.  Use the readonly attribute to prevent a user modifying it.  If you want the disabled look, simulate it with CSS.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.