Mysterious (to me) "object doesn't support this propery or method error - JavaScript HTML rollout

254 Views Asked by At

I'm getting the error above from Char 1 of the 4th line... No clue what's throwing it? I'm sure its something simple that I don't see...

out = out + "<b>Select Box Information</b><br><br> The name of the select box is: skeletor. A play on the word selector.<br>"
out = out + "The options for the select box are, Default Value, Option 2, Option 3, Option 4 and Option 5.<br>"
out = out + "The values for each option, from top to bottom, are: " + lucy.skeletor.option(0) + ", "
out = out + lucy.skeletor.option(1) + ", " + lucy.skeletor.option(2) + ", " + lucy.skeletor.option(3)
out = out + ", " + lucy.skeletor.option(4) + ".<br><br>"
out = out + "The index of the first option in the select box is: 0. The location of the user-selected option is: " + lucy.skeletor.value + ".<br><br>"
2

There are 2 best solutions below

3
On BEST ANSWER

I'd think lucy.skeletor.option(1) will be the problem here. If lucy.skeletor is a genuine select element, it contains an options array. That array can be referenced like: lucy.skeletor.options[n]

furthermore, if you concatenate, you could do:

out += somestring+someotherstring+morestrings ... etc
0
On

out = out + ... is ok, just not necessary. Your problem is using .option(1) which is accessessing a non-existing collection

If skeletor is a then the correct syntax for newer browsers is

lucy.options[1].value or .text

Here is what I think you meant

var out = "";
out += "<b>Select Box Information</b><br><br> The name of the select box is: skeletor. A play on the word selector.<br>"
out += "The options for the select box are, Default Value, Option 2, Option 3, Option 4 and Option 5.<br>"
out += "The values for each option, from top to bottom, are: "
var opts=[]; 
for (var i=0;i<lucy.skeletor.options.length;i++) opts.push(lucy.skeletor.options[0].text); 
out += opts.join(", ");
out += ".<br><br>"
out += "The index of the first option in the select box is: 0. The location of the user-selected option is: " + lucy.skeletor.value + ".<br><br>"