Topic awaiting preservation: XMLHttpRequest (Page 1 of 1) |
|
---|---|
Neurotic (0) Inmate Newly admitted From: |
posted 01-11-2012 23:42
I want to send to parameters to a different page but can't get it to work 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'>************ </span><br><br> page 2 <?php $ProdId=$_GET["q"]; $Id=$_GET["i"]; echo $ProdId."*----*".$Id; echo $_SERVER['QUERY_STRING']; ?>
|
Obsessive-Compulsive (I) Inmate From: |
posted 01-12-2012 18:05
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. |