I'm trying to get a variable value (account) from the user and then send it to my script. I'm using this code:
<p><input type="text" id="accountField"=>Enter Number</input>
<button onclick="test()">Submit</button></p>
<script>
function test(){
var getAccount = document.getElementById("accountField").value;
console.log(getAccount);
return getAccount;
}
var account = test();
</script>
<script type="text/javascript" src="test.js"></script>
The problem is that the src script runs without waiting for the user input and so it fails. I've tried the defer='defer' but that didn't make it wait.
I just need to get one number from the user and add it to my script as a variable. I was able to get it to work using the windows prompt, but I would rather avoid that if possible.
EDIT: I'm trying to make a synchronous call, not an asynchronous call. I am getting some information from a form and then making a call with that information. I don't want to call the external script unless the user answers the question in my form.