showing results for - "generate random key in javascript"
Joy
28 Mar 2019
1<h6>Content 1:</h6>
2<textarea class="content1" name="content1" id= "content1" spellcheck="false" onclick="content1()" readonly></textarea>
3<h6>Content 2:</h6>
4<input type="text" class="content2" name="content2" id= "content2" spellcheck="false" onclick="content1()" readonly>
5
6
7<script>
8var random_generator1 = document.getElementById('content1') 
9random_generator1.innerHTML = create_random_generator(10) 
10var random_generator2 = document.getElementById('content2') 
11random_generator2.innerHTML = create_random_generator(20) 
12                                        
13function create_random_generator(string_length){
14    var random_string = ''
15    var char = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'
16    var i
17    
18    for(i = 0; i < string_length; i++){
19        random_string = random_string + char.charAt(Math.floor(Math.random()* char.length))
20    }
21    return random_string
22}
23</script>