0

Hey i have got a form that auto grants random numbers on page load but is there anyway i can get it to grant random characters instead or even both numbers and characters?

Heres what i got:

document.getElementById('Codefield').value = Math.floor(Math.random() * 1000000000000);
<form method='post' action='secret_code.php'>
  <input type="text" name="" size="40" id="Codefield">
  <input type="submit" class='side' value="Get Code" id="submit" name="submit">
</form>
Omid Nikrah
  • 2,444
  • 3
  • 15
  • 30

1 Answers1

-1

You can do it by the following code:

document.getElementById('Codefield').value = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
<form method='post' action='secret_code.php'> 
    <input type="text" name="" size="40" id="Codefield"> 
    <input type="submit" class='side' value="Get Code" id="submit" name="submit"> 
</form>
Omid Nikrah
  • 2,444
  • 3
  • 15
  • 30