Topic: XMLHttpRequest (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=32513" title="Pages that link to Topic: XMLHttpRequest (Page 1 of 1)" rel="nofollow" >Topic: XMLHttpRequest <span class="small">(Page 1 of 1)</span>\

 
nalita123
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Jan 2012

IP logged posted posted 01-11-2012 23:42 Edit Quote

I want to send to parameters to a different page but can't get it to work


page 1 - JS


code:
<script type="text/javascript">

   function showUser(str) 
{ 
if (str=="") 
  { 
  document.getElementById("txtHint").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) 
    {var x=document.getElementById("co").value; 
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText; 
	
    } 
  } 
 
xmlhttp.open("GET","page2.php?q="+str+"&i="+x,true); 
xmlhttp.send(); 
} 

 </script>




page 1 - html - php




<form action='' name='InsertOrder'  method='post' >

Select Company:
<select name='CoDropDown[]' id='co'><?php
for ($i=0; $i < sizeof($Location['LocName']); $i++)
{
  echo "<option value='".$Location['SplitId'][$i]."'> ".$Location['LocName'][$i]."</option>";
 }?>
</select>


Equipment Type:
<select name='EquipTypeDropDown[]' id='equi' onchange="showUser(this.value)" ><?php
for ($i=0; $i < sizeof($EquipType['Equip']); $i++)
{
  echo "<option value='".$EquipType['Id'][$i]."'> ".$EquipType['Equip'][$i]."</option>";
 }?>
</select>
<span id='txtHint'>************&nbsp; &nbsp;</span><br><br>



page 2 


<?php

$ProdId=$_GET["q"];

$Id=$_GET["i"];
echo $ProdId."*----*".$Id;
 echo $_SERVER['QUERY_STRING']; 

?>


[Edit TP: added code tags]
I've been playing with it for hours but cant get it to work. Can anyone tell me why. It seems like the get element by id is not working inside the function. but it does outside of it. What am I doing wrong?

(Edited by Tyberius Prime on 01-12-2012 10:01)

nalita123
Obsessive-Compulsive (I) Inmate

From:
Insane since: Jan 2012

IP logged posted posted 01-12-2012 18:05 Edit Quote

Found the mistake. Var x has to be outside any if / else staments (inside the js function). I can't believe it took me a day to find the error. I hope it helps someone.



Post Reply
 
Your User Name:
Your Password:
Login Options: Remember Me On This Computer
 
Your Text:
Loading...
Options: Show Signature
Enable Slimies
Enable Linkwords

« BackwardsOnwards »

Show Forum Drop Down Menu