문제

I have two functions defined that are basically supposed to get a value from drop down menu and depending on what was selected, throw up a table and form using AJAX.

Here are my 2 functions:

function showParts(str)
{
if (str=="")
  {
  document.getElementById("partvalues").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("partvalues").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getparts.php?q="+str,true);
xmlhttp.send();
}

function showOrders(str)
{
if (str=="")
  {
  document.getElementById("otherparts").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("otherparts").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","formOrder.php?q="+str,true);
xmlhttp.send();
}
</script>

I tested those 2 functions and they both work properly. I have 2 PHP pages which have a query to retrieve the appropriate values. But the problem is, when I try to run both of them as onchange events, neither of them work.

echo "<select name = finishgood_list onchange = showParts(this.value); showOrders(this.value)>";
        while ($row = mysql_fetch_array($result))
        {
            echo "<option value='" . $row['fg_id'] . "'>" . $row['fg_id'] . "</option>";
        }

If I try and nest the functions within parenthesis, neither of them work when I change values in my drop down menu. I tested them individually and they both work fine but I cannot get them both to work at the same time.Only the first function is executing so If I change those around the showOrder will work but not the other.

Are there any problems here? If I can't do it this way, is there another way to retrieve the appropriate values dynamically when selecting a value from a drop down menu?

도움이 되었습니까?

해결책

At a guess, the most obvious change is from

echo "<select name = finishgood_list onchange = showParts(this.value); showOrders(this.value)>";

to

echo "<select name = 'finishgood_list' onchange = 'showParts(this.value); showOrders(this.value);' >";

I.e wrap the attributes in quotes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top