Sean O wrote: > Hey Scott, Hey Sean,
> Glad to be of help. Some of the more involved jQuery functions take a while > getting used to, and I've still certainly got a lot to learn... It really does take some time, and I'm still not following some of the subtleties yet. Example below <grin> > Once you get the basic mechanics of your form working, you may want to add a > visual cue to your users that fields have been updated. I used the nifty > highlightFade plugin: > http://jquery.offput.ca/highlightFade/ > to highlight autocompleted fields in a zipcode lookup I created (the basis > for the code I gave you) > > Or even an annoying audio cue, using my jMP3 plugin (shameless plugin > plug!): > http://www.sean-o.com/jquery/jmp3/ > ...perhaps a soft, brief harp sound -- player hidden, and set to autoplay on > completion. That's a great idea -- I will be looking at both of them. Quick question though -- I've been trying to make the code you posted work, and the call is getting through to the php script properly, and the php script is correctly (I think) returning the XML to my program. At least, firebug is showing what I expect as the response. However, the two functions that fetch the returned values are giving me nothing (var state = $("state",xml).text(); var city = $("city",xml).text();) I put a debugger stop right after those functions, and I get empty variables. The response string that I'm sending back is... <response><city>Columbus</city><state>Oh</state></response> I am assuming that the returned xml is defined in the $ object, but I don't know how to figure out what's wrong. Any suggestions? Also -- can I replace the value of INPUT fields? That's what these are on the form, of course. -Scott > > ;) > > > ________ > SEAN O > > > > > Scott Sharkey wrote: >> 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/ >> >> > _______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
