codingcodeddode
12-01-2012, 08:45 PM
If I wanted a user to type in their 3 favorite colors separated by spaces into a textbox, how could I grab their input and put it into an array?
<script>
var runThis = function(){
var userInput = document.getElementById('block').value;
var thisArray = new Array(userInput);
document.getElementById('mySpan').innerHTML = userInput;
x = userInput;
var thisArray = new Array(x);
y = thisArray;
return y;
}
</script>
<body>
<input id='block'>
<br>
<input type='button' onclick='runThis();' value='Click Here'>
<br>
<span id='mySpan' onclick='test();'>
</span>
</body>
<script>
var runThis = function(){
var userInput = document.getElementById('block').value;
var thisArray = new Array(userInput);
document.getElementById('mySpan').innerHTML = userInput;
x = userInput;
var thisArray = new Array(x);
y = thisArray;
return y;
}
</script>
<body>
<input id='block'>
<br>
<input type='button' onclick='runThis();' value='Click Here'>
<br>
<span id='mySpan' onclick='test();'>
</span>
</body>