I tried making most of the changes you suggested except for the loop idea, but nothing is getting updated in my form at this point. For now I'd like to focus on the customer section, then once that's working I can go back to the product lines.
Btw, this is for a school project in my Databases course, and I need a working demo by Friday, Nov 30 :)
Anyway, here's the form for the customer info:
[PHP]<form action="studio_ update.php" method="post">
<?php
echo "<script src='autofill_c ustomer.js'></script>";
echo "Customer Info:<br>";
echo "Last:
<input type='text' size=20 name='last' onblur='showCon tact(first.valu e, this.value)'>       ";
echo "First:
<input type='text' size=20 name='first' onblur='showCon tact(this.value , last.value)'><b r>";
echo "Phone 1:  
<input id='cust_phone1 ' type='text' size=12 name='phone1'> <br>";
echo "Phone 2:  
<input id='cust_phone2 ' type='text' size=12 name='phone2'> <br>";
echo "Address:  
<input id='cust_addres s' type='text' size=50 name='address'> <br>";
echo "<hr>";[/PHP]
The form close tag is further down after the products.
Below is my javascript code:
- var xmlHttp
-
-
function showContact(first, last)
-
{
-
xmlHttp=GetXmlHttpObject()
-
if (xmlHttp==null)
-
{
-
alert ("Browser does not support HTTP Request")
-
return
-
}
-
var url="get_customer.php"
-
url=url+"?f="+first
-
url=url+"&l="+last
-
url=url+"&sid="+Math.random()
-
xmlHttp.onreadystatechange=stateChanged
-
xmlHttp.open("GET",url,true)
-
xmlHttp.send(null)
-
}
-
-
function stateChanged()
-
{
-
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
-
{
-
document.getElementById("cust_phone1").innerHTML=xmlHttp.responseXML
-
document.getElementById("cust_phone2").innerHTML=xmlHttp.responseXML
-
document.getElementById("cust_address").innerHTML=xmlHttp.responseXML
-
}
-
}
And finally my server side PHP script to get the customer info:
[PHP]<?php
include "connect.ph p";
$first=$_GET["f"];
$last=$_GET["l"];
$sql="SELECT customer_id, phone1, phone2 FROM Customer WHERE first = '".$first."' AND last = '".$last."'" ;
$result = mysql_query($sq l);
// Row contains the phone numbers
$row = mysql_fetch_arr ay($result);
$id = $row['customer_id'];
// Addr contains only the address
$sql = "SELECT address FROM Customer_Addres s WHERE customer_id = '".$id."'";
$addr = mysql_query($sq l);
$addr = mysql_fetch_arr ay($addr);
echo "<?xml version='1.0' encoding='ISO-8859-1'?>
<person>";
echo "<cust_phon e1>" . $row['phone1'] . "</cust_phone1>";
echo "<cust_phon e2>" . $row['phone2'] . "</cust_phone2>";
echo "<cust_address> " . $addr['address'] . "</cust_address>";
echo "</person>";
mysql_close();
?>[/PHP]
So here's my understanding of what should happen (which was sorta working before, just the updates were in the wrong location on the form):
1) I enter a first or last name, and tab out of that box.
2) The javascript function showCustomer() executes w/ the contents of the firstname and lastname text boxes, and sets the phone and address text boxes to be filled by the results of the responseXML generated by the PHP form.
3) The PHP script gets called, which gets the phone and address out of the database, and sends back an XML document w/ the appropriate info. This then gets parsed (by I don't know what exactly) and filled into the appropriate fields.
As I said, no text fields are being updated now. I think I've made all the changes you suggested (w/o the loop for the product at this point, of course), but I would think the customer should still be getting updated now. I don't see how a loop would be practical for this particular section. Should my echo <id_name> row[id] </id_name> lines include the <input type='text'> tags as well?
As for the products, since each product line has its onBlur event set to showPrice(str, i), I pass the line number into the function, so my PHP script should only update the most recently changed product line, not all the lines every time.
Again, any help or insight is appreciated.
Dybs