Generate Random Characters Using JavaScript
Submitted by razormist on Monday, March 9, 2020 - 21:38.
In this tutorial we will create a Generate Random Characters using JavaScript. This code will generate random characters when user click the button. This code use onclick to call a specific method that dynamically generate a random characters with the use of dot notation charAt() that randomly change the character index position base on the given length. This program is a user-friendly feel free to use it in your system.
We will use JavaScript to allow you to implement complex things on web pages. It enables you to create dynamically updating content and add some interactive visual for the user transactions.
There you have it we successfully created a Generate Random Characters using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Getting Started:
This is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.The Main Interface
This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-4">
- <form>
- <div class="form-group">
- <input type="text" id="password" placeholder="Password here..." class="form-control" readonly = "readonly"/>
- </div>
- </form>
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will generate a characters when the button is clicked. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js directory- var keys = "abcdefghijklmnopqrstubwsyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
- var password = '';
- function generatePassword(){
- password='';
- for(i=0; i<12; i++){
- password+=keys.charAt(Math.floor(Math.random()*keys.length));
- }
- document.getElementById('password').value=password;
- }
Add new comment
- 237 views