I am trying to generate a custom URL with appended variables that are randomly generated.
Example:
http://example.com/page1234.jsp?id=LOCATION_ID&user=USER_NAME&pass=PASSWORD
I'm fine with all of the variable data being numeric, and have been trying to use this to generate the random numbers:
<p>Click the button to join.</p>
<button onclick="genID5()">Join</button>
<p id="generateID1"></p><p id="generateID2"></p><p id="generateID3"></p>
<script>
function genIDA() {
var x = Math.floor((Math.random() * 1000000000000) + 101);
document.getElementById("generateID1").innerHTML = x;
console.log(x);
}
function genIDB() {
var y = Math.floor((Math.random() * 1000000000000) + 101);
document.getElementById("generateID2").innerHTML = y;
console.log(y);
}
function genIDC() {
var z = Math.floor((Math.random() * 1000000000000) + 101);
document.getElementById("generateID3").innerHTML = z;
console.log(z);
}
function genID5() {
genIDA();
genIDB();
genIDC();
}
</script>
I am getting some nice big random numbers, and then I am trying to use this to append the URL:
function genURL() {
document.action = window.location.href = "http://example.com/page1234.jsp?id=" + X + &user= y + &pass= + z;
return true;
}
The URL function mostly works as far as pushing it to the Window object, and going to that URL - but getting the var values to insert is giving me a problem.
I am not sure if it is because they are not nested, but I am getting undefined errors. Ultimately I don't need/want the user to see the numbers, and if the page loaded and executed to the script and the loaded the destination, that would be OK as well. I wanted to see the output difference between the HTML and the Console, and having the button to execute it helped me see the steps.