-2

Need action to happen when page open and remove the bottom

<form name="randform">
Account Number: &nbsp;<input type="text" name="randomfield"     value="">&nbsp;
<input type="button" value="Create Account Number" onClick="randomString();">

Need the code to give random number ever time it open

  function randomString() {
  var chars = "0123456789";
  var string_length = 10;
  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;
}
HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47

2 Answers2

0

// need action to happen when page open

Try using window.onload

<script>
  function randomString() {
    var chars = "0123456789";
    var string_length = 10;
    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;
  }
  window.onload = randomString;
</script>
<form name="randform">

  Account Number: &nbsp;
  <input type="text" name="randomfield" value="">&nbsp;
  <input type="button" value="Create Account Number" onclick="randomString();">
</form>
guest271314
  • 1
  • 15
  • 104
  • 177
0
<script>
    var main_form = "[data-inSet=hook]";
    var ActionFild = "[data-inSet=randomfield]";

    $(main_form).ready(function () {
        //the Function You want To Fire -=>
        //i am just traing to get window height and output in consol :-p
        console.log( window.innerHeight+"px");//my action
    });
    /*
    u can also run the function  if the input load . just change $(main_form) -=> [ to ] <=-$(ActionFild);
    need more info plz comment bellow 
    */``
</script>
insCode
  • 1,227
  • 14
  • 10