-
Suposse user hits
SPACEin a text -field. I want to check the value in the select -box. I useinput.addEventListener('keydown', function(e)...to track theSPACE-hitting-point but how can I get the value of the select block<select id='topic'><option value="hello"></option> ...</section>? -
How can you stdout the value of the selected index? Cannot understand why not below.
var el = document.getElementById("topic"); var topicValue = el.options[el.selectedIndex].value; // PROBLEM: Won't do anything (despite inside <script> -tags) window.alert(topicValue);
where the topic is the select <select id="topic"[^>]*>[^<]*</select>.
The events work in the select, not to options but just conditional to the script.
[Answers to the updated]
document.getElementById('topic').options.selectedIndexormySelect.options[selectedIndex].value(does not work with me). And apparently you could create a form to which you could refer bydocument.forms['topic'].elements[id]but not sure about this one. More.dictionary = {0:"topic", 1:"hello",...,n:"topic_{n}"}and then use thegetElementById('topic').selectedIdas a key and forget the values. Not solved but rounded.[Update] I think I solved it, just
el.value, noselectedIndexneeded: