Jump to content

Got an error in xmlhttp.responseText


newphpcoder
 Share

Recommended Posts

Hi..

 

It's my first time to use ajax, and now I used ajax to get the value from select option then use that value.

 

here is my ajax code:

 

<script type="text/javascript">
var xmlhttp;  // Give the function a unique name, this is what your HTML will call to run the AJAX 
function select_code() {      // This is all just setting up the variable, ignore it     
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) {              
        //alert(xmlhttp.responseText);
       // alert(xmlhttp.readyState+" "+xmlhttp.status);
       
    document.getElementById("rows").innerHTML = xmlhttp.responseText;   
        //var mydata=xmlhttp.responseText;         
    }      
};      
var val = document.getElementById("lot_number");      
var lot_number = val.options[val.selectedIndex].text;       
var parameters = "lot_number="                      
                + lot_number;       
                xmlhttp.open("POST", "PickingForm.php", true);     
                xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");     
                xmlhttp.send(parameters);
//var mydata=xmlhttp.responseText;   
}

</script>

 

nad here is my PickingForm.php where the select option was in.

 

$query = "SELECT lot_number from wms WHERE (date_shelve IS NOT NULL) AND stock_item = '$ItemCode' AND (qty = orig_qty OR qty != '0.00') AND qty >= '$SubQty' ORDER BY qty";                 
$rows = mysql_query($query, $con); 

echo "<td><select name = 'lot_number' id='lot_number' onChange='select_code();'>";

//echo "<select name='lot_number' id='lot_number' onchange='MM_jumpMenu('parent',this,0)'>";
echo "<option></option>";                
  while ($record = mysql_fetch_array($rows))          
  {             
      echo "<option value = '{$record['lot_number']}'";             
      if ($lot_number == $record['lot_number'])                 
      echo "selected = 'selected'";             
       echo ">{$record['lot_number']}</option>";        
  }         
  echo "</select>";
  echo "</td>";  
  
  $lot_number = $_POST['lot_number'];
  
  $sql_bin = "SELECT bin_loc FROM wms WHERE lot_number = '$lot_number'";
  $res_bin = mysql_query($sql_bin, $con);
  
  while($row_bin = mysql_fetch_assoc($res_bin)){
      $bin_loc = $row_bin['bin_loc'];
      
  echo "<td><input type='text' name='bin_loc' id='bin_loc' value='$bin_loc'></td>";
  }

 

and when I select lot_code in select option:

 

I got an error:

 

document.getElementById() is null or not an object...

 

I don't know how can I solve this error:(

 

Thank you

 

 

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.