I'm trying to make a simple mad libs type game. To do so I need to do the following:
- Have space that user can input text
- Retrieve text that user inputted
- Assign text to variables using Javascript
- Place variables in Mad libs
I know how to do this using something like:
var userAnswer = prompt("Give me an answer");
However, I want to get the input from a text input field. I was trying to do the following but I got stuck:
- Have input area with id="input1"
- Create function that takes content of #input1 and assign to a variable.
- Use button to run the function
I will then later use these variables in my story
<label for='input1'>Verb + ing</label><input id='input1'>
<script>
var setInputs = function() {
var space1 = document.getElementById("input1").innerHTML;
}
</script>
<button onclick="setInputs">Click me</button>
I'm I going about this the correct way?
Fiddle: http://jsfiddle.net/6rjf5k9n/
document.getElementById("input1").value