Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Got An Error In Xmlhttp.reponsetext

xml innerHTML

  • Please log in to reply
1 reply to this topic

#1 newphpcoder


    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 05 June 2012 - 09:40 PM

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.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");	
//var mydata=xmlhttp.responseText;  
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
  • 0

#2 BlackRabbit


    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 17 June 2012 - 01:40 PM

well, i have not the entire code here as for giving the best answer, but first things first,

in select_code() you have 2 calls to document.getElementByID , one to "rows" and the other to "lot_number"

in the code you give it looks like lot_number exists and it is ok, since it is the one calling select_code()
so maybe you should check for the rows object to be present, and of course to be part of document, cause maybe you go it on a frame or window, etc and the getelement does not get to find it for an scope issue.
  • 0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download