I have a form for adding a new username and password to a site. I'm trying to add a button which generates a 12character password and puts it into the password text box. Everytime this button is pressed it should delete the password in already and add in another 12 char password.
This is my layout: http://snag.gy/L4woo.jpg
Here is how my form:
<form method="post" action="addNewLogin.php" name="addUserLoginForm" id="addUserLoginForm" onsubmit= "return validateNewLoginForm()" >
<input type="hidden" name="submitAttempt" value="true"/>
<table style="background-color: White; padding:20px;" align="center">
<tr>
<td style="width:180px;">
<label style="margin-left:400px;">Username</label>
</td>
<td style="width:420px;">
<input name="username" type="text" style="width:140px;" onchange= "return usernameValidation(this)" />
</td>
</tr>
<tr>
<td>
<label style="margin-left:400px;">Password</label>
</td>
<td>
<input name="password" type="password" style="width:140px;" onchange= "return passwordValidation(this)"/>
</td>
<td style="margin-right: 200px;">
<button type="password" type= "text" onclick="return generateKey()">Generate Password!</button>
</td>
</tr>
</table>
<div align="center"><input type="submit" value="Add Login Details For New User" /></div>
</form>
My usernames and password validate through a separate JavaScript function using standard regex
And here is my 12character generate password function:
public function generateKey()
{
$random_bytes = openssl_random_pseudo_bytes(9);
$random_string = mysql_escape_string(str_replace(array(1 => "+",2 => "/"), array(1 => "-", 2 => "_"), base64_encode($random_bytes)));
return $random_string;
}
I have no idea how to click on this button to apply this function to the required textbox. hope you can help. thanks