|
Re: [jQuery] Ajax to update multiple fields: msg#01147lang.javascript.jquery
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 (!@mysql_select_db($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 > discuss@xxxxxxxxxx > http://jquery.com/discuss/ > > -- View this message in context: http://www.nabble.com/Ajax-to-update-multiple-fields-tf2437343.html#a6796884 Sent from the JQuery mailing list archive at Nabble.com.
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | [jQuery] $(document).load() and friends, Mika Tuupola |
|---|---|
| Next by Date: | Re: [jQuery] $(document).load() and friends, Mark Gibson |
| Previous by Thread: | [jQuery] Ajax to update multiple fields, Scott Sharkey |
| Next by Thread: | Re: [jQuery] Ajax to update multiple fields, Scott Sharkey |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |