DISABLE ADBLOCK

ADBlock is blocking some content on the site

ADBlock errore

HTML select onchange multiple events not working

StackOverflow https://stackoverflow.com/questions/13215548

Question

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?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow