Jump to content

not going into an onChange event after dropdown list with Ajax


kwstephenchan

Recommended Posts

Hi,

I am sorry about the crumpsy title as I do not know how to put it.

My problem is:

I have a dependable dropdown list that help produce a list of states.

But I want to select a particular state and change the information of that state, so I put an onChange 

event so that supposedly details of that state will be produced for modification.

But the script is not answering the onChange event (have put an alert statement in the function and it is not showing it)

I am totally new to Ajax and using this to learn, would someone please help point out what's wrong with it.

Thanks in advance.

The html are:

 

                   <tr valign="baseline">
                       <td width="30%" align="right" class="lbtxt"><?php echo "Country : "; ?></td>
                       <td><select name="m_country" onChange="getState(this.value)">
                      <option value=""><?php echo "Select Country"; ?></option>
<?php
                           mysql_select_db($database_conEstate, $conEstate);
                           $cRS = mysql_query("SELECT * FROM country order by ".$lang."countryname asc") or die(mysql_error()); 
                  while ($crow = mysql_fetch_assoc($cRS)) {
                           echo "<option value="; echo $crow['countryid']; echo ">"; 
  echo $crow[$lang."countryname"]; echo "</option>";
                             }
?>
                          </select>
   </td>
                    </tr>
  
                    <tr valign="baseline">
                        <td width="30%" align="right" class="lbtxt"><?php echo "State :"; ?></td>
                        <td><div id="statediv"><select name="m_state" onChange="lookupstate('<?php echo $countryid; ?>','<?php echo $stateid;?>','<?php echo $showen; ?>','<?php echo $showbg; ?>','<?php echo $showgb;?>' );"> >
                      <option><?php echo "Select Country First"; ?></option>
                           </select></div>
</td>
                    </tr>
 
The javascripts are:
 
var urlstate = "lookupstate.php?param="; // The server-side script
//alert{"here before lookupstate");
function lookupstate(countryid,stateid,showen,showbg,showgb) {
alert("in lookupstate");
  var http;
    if (window.XMLHttpRequest) {
         // code for IE7+, Firefox, Chrome, Opera, Safari
         http = new XMLHttpRequest();
    }
    else {
         // code for IE6, IE5
         http = new ActiveXObject("Microsoft.XMLHTTP");
    }
  var id1=countryid;
  var id2=stateid;
  var showen=showen;
  var showbg=showbg;
  var showgb=showgb;
//  var showid=showid;
  var cid1 = document.getElementById(id1).value+","+document.getElementById(id2).value;
alert("cid1="+cid1);
  http.open("POST", urlcountry + escape(cid), true);
      http.onreadystatechange = function()
    {
      try
      {
        if (http.readyState == 4 )
        {
//          results = http.responseText;
//          document.getElementById(showen).value =  results;
          results = http.responseText.split(",");
          document.getElementById(showen).value =  results[0];
          document.getElementById(showbg).value =  results[1];
          document.getElementById(showgb).value =  results[2];
 if (cid=="00") {
            document.getElementById(showen).value =  "";
            document.getElementById(showbg).value =  "";
            document.getElementById(showgb).value =  "";
} else {
//            document.getElementById(showid).disabled=true;
}
        }
      }
      catch(e){}
    }
      http.send(null);
  
//  http.onreadystatechange = handleHttpResponse;
//  http.send(null);
}
 
 
 
 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.