I asked for input on the name of a team because I am trying to create a program that will create a table based on point scores. I have to write my input code in JS because it is within an OnClick Function. I don't, however, understand how to store the user input (in a variable or otherwise.)
I've tried methods such as storing the actual document.write in a variable.
<!DOCTYPE html>
<html>
<body>
<h1>Soccer Table Generator</h1>
<h3>How Many Teams Would You Like?</h3>
<select id="num_of_teams">
<option value="Select" selected>Select</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<script>
var menu = document.getElementById("num_of_teams");
menu.addEventListener("change", generateData);
function generateData(event) {
if (menu.value == '2') {
alert("You have selected 2 teams. Would you like to proceed?");
document.write ("What is the name of your first team?");
var teamone = document.write ("<input type = 'text' value =
'input here'<input>");
document.write ("What is the name of your second team?");
} else if (menu.value == '3') {
alert("You have selected 3 teams. Would you like to proceed?");
} else if (menu.value == '4') {
alert("You have selected 4 teams. Would you like to proceed?");
}
}
</script>
</body>
</html>
I would expect for the input to be stored in a variable and printed (when I used the code for it to be printed), but when I try that it shows up undefined.