Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-27-2012, 09:11 PM   PM User | #1
patsfans
New to the CF scene

 
Join Date: May 2011
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
patsfans is an unknown quantity at this point
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.
patsfans is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:43 AM.


Advertisement
Log in to turn off these ads.