How to generate random numbers when refreshing the page? There is such a field:

<div class="checkout-billing-content-field checkout-billing-content-total"> <div class="checkout-billing-content-title"> <span>ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅</span> </div> <div class="checkout-billing-content-amount"> <span class="checkout-currency"> <input type="text" class="input-text" onclick="$(this).select();" style="margin-right: 50px;" readonly value="bill[mnkOmfrNCJROaRw]"> - вмСсто этих символов Π½ΡƒΠΆΠ½Π° гСнСрация случайных чисСл </span> </div> </div> 

    3 answers 3

    Genniruet 15 digit number

     document.getElementsByClassName('input-text')[0].value= "bill[" + parseInt(Math.random() * 1000000000000000) + "]"; 
     <div class="checkout-billing-content-field checkout-billing-content-total"> <div class="checkout-billing-content-title"> <span>ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅</span> </div> <div class="checkout-billing-content-amount"> <span class="checkout-currency"> <input type="text" class="input-text" style="margin-right: 50px;" readonly > - вмСсто этих символов Π½ΡƒΠΆΠ½Π° гСнСрация случайных чисСл </span> </div> </div> 

    Dobavlyaem before </body>

     <script> document.getElementsByClassName('input-text')[0].value= "bill[" + parseInt(Math.random() * 1000000000000000) + "]"; </script> 
    • Excellent what you need, now how to combine all this? I can not understand - Maxim
    • what exactly to combine? - L. Vadim
    • document.getElementsByClassName ('input-text') [0] .value = "bill [" + parseInt (Math.random () * 1000000000000000000) + "]"; - Max
    • <div class = "checkout-billing-content-field checkout-billing-content-total"> <div class = "checkout-billing-content-title"> <span> Note </ span> </ div> <div class = "checkout-billing-content-amount"> <span class = "checkout-currency"> <input type = "text" class = "input-text" style = "margin-right: 50px;" readonly> - instead of these symbols, random number generation is needed </ span> </ div> </ div> - Max.
    • combine this to work in index.html - Max.

     $(function(){ var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for(var i=0; i < 10; i++) { text += possible.charAt(Math.floor(Math.random() * possible.length)); } $(".input-text").val("bill[" + text + "]"); }) 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="checkout-billing-content-field checkout-billing-content-total"> <div class="checkout-billing-content-title"> <span>ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅</span> </div> <div class="checkout-billing-content-amount"> <span class="checkout-currency"> <input type="text" class="input-text" onclick="$(this).select();" style="margin-right: 50px;" readonly value="bil[mnkOmfrNCJROaRw]"> </span> </div> </div> 

      For such there is Math.random . Generate a random number, and then put the value you need

       (function() { var num = Math.round((Math.random() * 100) * (Math.random() * 100)); document.querySelector('.input-text').value = 'bill['+num+']'; })(); 
       <div class="checkout-billing-content-field checkout-billing-content-total"> <div class="checkout-billing-content-title"> <span>ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅</span> </div> <div class="checkout-billing-content-amount"> <span class="checkout-currency"> <input type="text" class="input-text" onclick="$(this).select();" style="margin-right: 50px;" readonly value="bill[]"> </span> </div> </div>