Php IE中元素的空值

Php IE中元素的空值,php,javascript,html,Php,Javascript,Html,firefox中的代码正在运行。在IE中,警报为空 <select id="ronny" name="ronny" onchange="AjaxPost();alert(document.getElementById('ronny').value);"> <option id="selected_ronny">All</option> <?php foreach($d_ronny as $ronny) {

firefox中的代码正在运行。在IE中,警报为空

<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>

全部的

对于onchange属性,必须编写如下代码:

onchange="AjaxPost();alert(this.options[selectedIndex].value);"
如果要使用id,请将
thi
s替换为
document.getElementById('ronny')


你能发布AjaxPost()的代码吗?发布很好。问题是select的值。如果删除对
AjaxPost()的调用你可能会发现它是有效的,所以我们需要看看为什么会中断。谢谢!但是我有一个问题..我想稍后在其他JS中使用所选索引,我有一些。那么我怎样才能用id制作呢?@chelmertz:谢谢你的编辑@罗尼:我已经更新了答案。谢谢!但我在ie和ff中有一个错误-
“selectedIndex”未定义
它对我有效,但请尝试:
警报(document.getElementById('ronny')。选项[document.getElementById('ronny')。selectedIndex].value)
onchange="AjaxPost();alert(document.getElementById('ronny').options[selectedIndex].value);"