Top Ad unit 728 × 90

 

Live Demo


 

Follow these steps in your blog or site

Step 1

Add the following code to your head:
<script language="javascript" type="text/javascript">
function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 8;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
document.randform.randomfield.value = randomstring;
}
</script>

Variables to set:

chars - The random string will be created from these characters.
string_length - The length of the random string.

Step 2

Use the following code for your text field and button:
<form name="randform">
<input type="button" value="Create Random String" onClick="randomString();">&nbsp;
<input type="text" name="randomfield" value="">
</form>

Post a Comment

 
Top