Gayan Chaturanga Gayan Chaturanga - 4 months ago 15
Ajax Question

Call two function() by one Onchange

im going to get some data from database by using Ajax.
could you please let me know the way that i can trigger two function() by change a value of specified dropdown list using "OnChange"

note: most of the time system show only showhistory() function output

my existing codes

.............................................

<select name="po_no" onchange="showsize(this.value);showhistory(this.value);">


........................................................

<script>

function showhistory(str)
{if (str=="")
{
document.getElementById("txtHistory").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("txtHistory").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gethistory2.php?s="+str,true);
xmlhttp.send();
}
</script>


<script>
function showsize(str)
{
if (str=="")
{
document.getElementById("sizeHint1").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
xmlhttp1=new XMLHttpRequest();
}
else
{
xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp1.onreadystatechange=function()
{
if (xmlhttp1.readyState==4 && xmlhttp.status==200)
{
document.getElementById("sizeHint1").innerHTML=xmlhttp1.responseText;
}
}
xmlhttp1.open("GET","getsize5.php?q="+str,true);
xmlhttp1.send();
}
</script>

Answer

call your second function on success of the first function

<select name="po_no" onchange="showhistory(this.value);">



<script>

 function showhistory(str)
 {if (str=="")
   {
  document.getElementById("txtHistory").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("txtHistory").innerHTML=xmlhttp.responseText;
    showsize(str);
}
 }
xmlhttp.open("GET","gethistory2.php?s="+str,true);
xmlhttp.send();
 }

 function showsize(str)
 {
 if (str=="")
  {
   document.getElementById("sizeHint1").innerHTML="";
   return;
   } 
 if (window.XMLHttpRequest)
   {
   xmlhttp1=new XMLHttpRequest();
    }
 else
   {
   xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
   }
xmlhttp1.onreadystatechange=function()
   {
   if (xmlhttp1.readyState==4 && xmlhttp.status==200)
     {
    document.getElementById("sizeHint1").innerHTML=xmlhttp1.responseText;
    }
    }
  xmlhttp1.open("GET","getsize5.php?q="+str,true);
  xmlhttp1.send();
  }
 </script>
Comments