CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ajax and Design (http://www.codingforums.com/forumdisplay.php?f=55)
-   -   Populating another field via Ajax (http://www.codingforums.com/showthread.php?t=266473)

patsfans 06-27-2012 09:11 PM

Populating another field via Ajax
 
I've got a form where I have two text fields. The first one is an autocomplete field that loads two variables, "item" and "description" via AJAX as a user enters in letters.

What I'm trying to do is the following:

When they click on the item, it populates the field with the item name, but I'd like for it to next populate the adjacent textfield with the description onblur (ie: when the user moves on to another field).

Here's the code:

PHP Code:

$().ready(function() {
    $(
"#item1").autocomplete("model_query.php", {
        
width260,
        
matchContainstrue,
        
//mustMatch: true,
        //minChars: 0,
        //multiple: true,
        //highlight: false,
        //multipleSeparator: ",",
        
selectFirstfalse
    
});
}); 

and the PHP script:

PHP Code:

$q strtolower($_GET["q"]);
if (!
$q) return;

$sql mysql_query("SELECT item as item_name, description from catalog where item LIKE '%$q%'");

while(
$rows mysql_fetch_array($sql)) {
    
$item$rows ['item_name'];
    
$descq $rows ['description'];
    echo 
"$item\n";


HTML:
PHP Code:

<div id="content">
    <
form autocomplete="off">
        <
p>
            
ITEM: <input type="text" name="item1" id="item1" />
</
div

These all work for the autocomplete form, but I'm at a loss as to how to move the "$description" variable into the javascript to populate that other field. Thanks in advance, and I appreciate any guidance you can provide.


All times are GMT +1. The time now is 01:57 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.