Append Random Number to URL in Script

3.9k Views Asked by At

I am trying to append a random number Math.floor((Math.random() * 10000) + 1);

To an embedded Formstack Form such as this one:

<script type="text/javascript" src="https://brynhowlett.formstack.com/forms/js.php/starbucks_orders__copy&"></script>

Int needs to go at the end right after the "&". I almost had it but keep messing up. I just need a push in the right directions.

Also I need it to be all inline. So I guess I would add the following above it the embedded form.

<script type="text/javascript" 

JS goes here

</script>
1

There are 1 best solutions below

3
On

Try using document.open() , document.write() , document.close()

<script>
  document.open();
  document.write("<script src=https://brynhowlett.formstack.com/forms/js.php/starbucks_orders__copy&" + Math.floor((Math.random() * 10000) + 1) + "><\/script>");
  document.close();
</script>
<body>
</body>