Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Where have the select options gone?

14 views
Skip to first unread message

justaguy

unread,
Jun 19, 2013, 11:09:51 AM6/19/13
to
Hi,

I'm puzzled by the following or more likely I don't know better.

I have this form with a select element and then I want to see what is selected on the same page, code is like this:

<select id="me">
<option>apple
<option>orange
...
</select>

<span id="findme"></span>

js after user has selected the above:

if (document.getElementById('me')) {
var ee = document.getElementById('me');
var eev = ee.options[ee.selectedIndex].value;
document.getElementById('findme').innerHTML = eev;
}
else {alert('WHY me field NOT FOUND');}

I expect to see the span id to display the value of the selected option
but I get the alert instead, what's wrong?

Thanks.

Luuk

unread,
Jun 19, 2013, 1:10:12 PM6/19/13
to
On 19-06-2013 17:09, justaguy wrote:
> <select id="me">
> <option>apple
> <option>orange
> ...
> </select>
>
> <span id="findme"></span>
>
> js after user has selected the above:
>
> if (document.getElementById('me')) {
> var ee = document.getElementById('me');
> var eev = ee.options[ee.selectedIndex].value;
> document.getElementById('findme').innerHTML = eev;
> }
> else {alert('WHY me field NOT FOUND');}

try:

<!DOCTYPE html>
<html>
<head>
<script language="javascript" type="text/javascript">
function xme() {
if (document.getElementById('me')) {
var ee = document.getElementById('me');
var eev = ee.options[ee.selectedIndex].value;
document.getElementById('findme').innerHTML = eev;
}
else {alert('WHY me field NOT FOUND');}
}
</script>
</head>
<body>
<select id="me" onchange="javascript:xme();">
<option value="Apple">apple
<option value="Orange">orange
...
</select>

<span id="findme"></span>
</body>
</html>

Danny

unread,
Jun 19, 2013, 1:55:38 PM6/19/13
to
To justaguy

use the onchange event handler in the Select element
check -> http://www.webdevout.net/test?0S&raw

justaguy

unread,
Jun 19, 2013, 2:16:48 PM6/19/13
to
When I looked deeply I noticed the id attribute was REMOVED! of course it couldn't be found. This FORM has los of elements, each has an id (it's been like that for a while...)
Some criminal is really EVIL... (hacked my computer and probably is being paid for doing that...)

0 new messages