views:

43

answers:

1

Hi!

This code in firefox is working. In IE the alert is empty.

<select id="ronny"  name="ronny" onchange="AjaxPost();alert(document.getElementById('ronny').value);">
   <option id="selected_ronny">All</option>
     <?php
       foreach($d_ronny as $ronny )
        {
        if($ronny == $_POST['ronny_select'])
        {
       echo "<option selected id='selected_ronny'>$ronny</option>";
        }
        else
        {
         echo "<option>$ronny</option>";
         }
       }
     ?>
</select>

The options are fox example : All abc 123 xyz When i select xyz, the alert shows xyz. In IE the alert is empty.

thank you!

+1  A: 

For the onchange attribute you have to code like this :

onchange="AjaxPost();alert(this.options[selectedIndex].value);"

If you want to use the id, replace this by document.getElementById('ronny') :

onchange="AjaxPost();alert(document.getElementById('ronny').options[selectedIndex].value);"
M42
thank you! but i have a problem..i want to use the selected index later in other JS and i have some. so how can i make it with id?
Ronny
@chelmertz: thanks for editing. @Ronny: i've updated the answer.
M42
thank you! but i have an error in ie and ff - `'selectedIndex' is undefined`
Ronny
It works for me, but Try : `alert(document.getElementById('ronny').options[document.getElementById('ronny').selectedIndex].value);`
M42
yes!!!!thank you!
Ronny
You're welcome.
M42
You can also upvote if this answer is useful
M42