<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<form name="myform">
<div class="form-group col-sm-3">
<div class="input-group">
<span class="input-group-btn">
<input type="button" class="btn btn-info" onclick="generate();" value="Generate Password">
<input type="hidden" name="length" value="10">
</span>
<input type="text" class="form-control" id="pass" placeholder="" name="gen_pass">
</div>
</div>
</form>
function randomPassword(length) {
var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP1234567890";
var pass = "";
for (var x = 0; x < length; x++) {
var i = Math.floor(Math.random() * chars.length);
pass += chars.charAt(i);
}
return pass;
}
function generate() {
myform.gen_pass.value = randomPassword(myform.length.value);
}