Sean,
That is an awesome answer - THANKS. I've been having trouble getting my
head around the way that AJAX works in jQuery, and this is the first one
that I've seen that "connected the dots" for me. THANK YOU.
-Scott
Sean O wrote:
> Hi Scott,
>
>
> Here's a suggestion:
>
> // autofill customer information from email
> $("#email").blur(function(){
> var emailaddr = $("#email").val();
> // AJAX send to email lookup, which outputs XML data
> $.post("checkemail.php",{ email: emailaddr },
> function(xml){
> // fill location fields with data
> returned
> from email lookup
> var state = $("state",xml).text();
> var city = $("city",xml).text();
> // etc. etc.
>
> // now update fields
> $("#state").attr("value",state);
> $("#city").attr("value",city);
> // etc. etc.
> });
> }
>
> checkemail.php does a db lookup & returns XML:
> (example uses PHP/MySQL - you could easily use other lookups like ASP/MSSQL,
> etc.)
>
> <?php
> header('Content-type: text/xml'); // output as XML
> $email=$_REQUEST['email'];
>
> // define dB connection vars...
>
> // connect to MySQL & load database
> mysql_connect('localhost',$username,$password);
> if ([EMAIL PROTECTED]($database)) { exit('<p>Unable to locate the ' .
> $database . ' database at this time.</p>'); }
>
> // retrieve customer data
> $query="SELECT * FROM customers WHERE (Email=$email)";
> $result=mysql_query($query);
> if (!$result) { exit('<p>Error performing query: ' . mysql_error() .
> '</p>'); }
>
> // close db
> mysql_close();
>
> while ($row = mysql_fetch_array($result)) {
> $city = $row['City'];
> $state = $row['State'];
> // etc. etc.
> }
>
> $returnXML =
> "<response><city>$city</city><state>$state</state>...</response>";
> echo $returnXML;
> ?>
>
>
>
> Scott Sharkey wrote:
>> Hi All,
>>
>> Brand new to jQuery, and looking for suggestions. I have a "customer"
>> form, that I need to do a lookup when they enter their email address,
>> and have it fill in the name, address, city, state, zip, etc if they are
>> already in the database.
>>
>> I am not following the ajax tutorials that I've found online so far very
>> well. Can anyone suggest some good, simple tutorial, or is there an
>> example piece of code somewhere that fills in multiple fields when one
>> changes?
>>
>> Thanks a bunch!
>>
>> -Scott
>>
>> _______________________________________________
>> jQuery mailing list
>> [email protected]
>> http://jquery.com/discuss/
>>
>>
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/