检索<select name =“value”> value </select>时firefox中的ajax问题

时间:2010-09-30 14:57:01

标签: php ajax firefox

亲爱的,所有人, 我正在使用firefox而不是IE来解决这个问题。

在第一个组合中,我正在扮演角色:

<tr>
<td>Select Role:</td>
<td>
<select name="usrrole" onChange="showuser(this.value)">
    <option value=''>Please Select</option>
<?php
  $rle = "select * from role_table";
  $dorle = mysql_query($rle);
  while($data = mysql_fetch_array($dorle)){
  echo ("<option value=$data[roleid]>$data[rolename]</option>");
}
?>
</select>
</td>
</tr>

<tr>
  <td> Select User </td>
  <td id="showus"> </td>  <!-- this is the div collected from ajax -->
</tr>
<tr>
  <td colspan=2> <input type='submit' name='submit' /> </td>
</tr>
<(>((((AJAX.JS))))

function GetXmlHttpObject()
{
 var xmlHttp=null;
 try
  {
      xmlHttp=new XMLHttpRequest();
  }
 catch (e)
  {
      try
       {
           xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
       }
      catch (e)
       {
           xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
   }
 return xmlHttp;
 }

function showusrinfo()
{
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
 {
  document.getElementById('showus').innerHTML=xmlhttp.responseText;
 }
}

function showuser(str)
{
  xmlhttp=GetXmlHttpObject();
  var url="../get.php";
  url=url+"?showus="+str;    
  xmlhttp.onreadystatechange=showusrinfo; 
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null); 
}
<(>((((GET.PHP))))

if(isset($_GET["showus"])){
$q  = $_GET["showus"];
$sql = "select uid,username from usertable where roleid='".$q."'";
$qry = mysql_query($sql);
$num = mysql_num_rows($qry);
if($num){
  $my = "<select name='touser'>";
  $my .= "<option selected value=''>Please Select</option>";
   while($result = mysql_fetch_array($qry)){
      $my .= "<option value='".$result['uid']."'>$result[username]</option>";
}
echo $my;
}
 else
{
 $notmy = "No Record";
}
echo $notmy;
}

现在,当我提交时会出现问题:

如果我在提交后打印变量,那么

在INTERNET EXPLORER中:

Array
(
  [usrrole] => 1
  [touser] => 3
  [submit] => submit
)

并在FIREFOX中:

Array
(
 [usrrole] => 1
 [submit] => submit
)

如您所见,AJAX中生成的变量仅在IE中显示而不在FF中显示,因此,在FF中运行代码时出错。

我是编程的新手并且坚持使用它,请帮忙。

欢呼声。

2 个答案:

答案 0 :(得分:0)

您应该阅读所选的选项值,而不是选择值

onChange="showuser(this.options[this.selectedIndex])"

答案 1 :(得分:0)

是的,没错,我需要输出 roleID ,而不是名称