I'm building a simple random word generator and am trying to have a <select> drop-down determine the number of words to be displayed. My idea was to have the <option>'s value contain the variables I want to be parsed into my function. However, it doesn't read the variables as I'd hoped, like it does in the first div, and instead writes the literal values. I'm sure there's a more elegant way to write this, but now I'm curious if I can even do it this way.
HTML:
<select id="wordCount" class="span2">
<option value="word1">1 Words</option>
<option value="word1+' '+word2">2 Words</option>
<option value="word1+' '+word2+' '+word3">3 Words</option>
<option value="word1+' '+word2+' '+word3+' '+word4">4 Words</option>
</select>
<input id="gen" type="submit" value="Generate">
<div id="wordBin"></div>
<div id="wordBin2"></div>
JavasSript:
$('#gen').click(function generateWords(){
var wordCount = document.getElementById('wordCount').value;
var wordbank = ['rock', 'paper', 'scissor', 'apple', 'beer', 'potato'];
var word1 = wordbank[Math.floor(Math.random()*wordbank.length)];
var word2 = wordbank[Math.floor(Math.random()*wordbank.length)];
var word3 = wordbank[Math.floor(Math.random()*wordbank.length)];
var word4 = wordbank[Math.floor(Math.random()*wordbank.length)];
var wordBin = document.getElementById('wordBin');
var wordBin2 = document.getElementById('wordBin2');
wordBin.innerHTML = word1+' '+word2+' '+word3+' '+word4;
wordBin2.innerHTML = wordCount;
});