Phil_n
09-13-2010, 01:47 PM
Hi, I originally posted this in the php section but then as my script has evolved and i was told i needed ajax I have the php side fully working and the whole thing working in IE but not Firefox.
Im trying to achieve a form in which the user will use a select box and the choice will determine what some text fields are filled with allowing the user to still edit the textfield sif necersary.
I have the script fully working in IE as stated but not in Firefox. Below is my code:
Form Page
<html>
<head>
<script type="text/javascript">
function showSupplier(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)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getsupplier.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onChange="showSupplier(this.value)">
<option value="">Select a person:</option>
<option value="1">Supplier1</option>
<option value="2">Supplier2</option>
<option value="3">Supplier3</option>
<option value="4">Supplier4</option>
</select>
</form>
<br />
<div id="txtHint"><b>Supplier info here</b></div>
</body>
</html>
getsupplier.php:
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', '', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("", $con);
$sql="SELECT * FROM suppliers WHERE Supplier_ID = '".$q."'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Supplier</th>
<th>Contact</th>
<th>Telephone</th>
<th>Email</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Supplier'] . "</td>";
echo "<td>" . $row['Contact'] . "</td>";
echo "<td>" . $row['Telephone'] . "</td>";
echo "<td>" . $row['Email'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Im trying to achieve a form in which the user will use a select box and the choice will determine what some text fields are filled with allowing the user to still edit the textfield sif necersary.
I have the script fully working in IE as stated but not in Firefox. Below is my code:
Form Page
<html>
<head>
<script type="text/javascript">
function showSupplier(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)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getsupplier.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onChange="showSupplier(this.value)">
<option value="">Select a person:</option>
<option value="1">Supplier1</option>
<option value="2">Supplier2</option>
<option value="3">Supplier3</option>
<option value="4">Supplier4</option>
</select>
</form>
<br />
<div id="txtHint"><b>Supplier info here</b></div>
</body>
</html>
getsupplier.php:
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', '', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("", $con);
$sql="SELECT * FROM suppliers WHERE Supplier_ID = '".$q."'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Supplier</th>
<th>Contact</th>
<th>Telephone</th>
<th>Email</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Supplier'] . "</td>";
echo "<td>" . $row['Contact'] . "</td>";
echo "<td>" . $row['Telephone'] . "</td>";
echo "<td>" . $row['Email'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>