Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

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 10-18-2012, 04:24 AM   PM User | #1
jlimited
New Coder

 
Join Date: Sep 2006
Posts: 32
Thanks: 5
Thanked 0 Times in 0 Posts
jlimited is an unknown quantity at this point
Autocomplete with Hidden ID

Hello,

I am trying to setup a simple data entry form and I am new to JQUERY. I need to return my database ID of the select autocompleted item in a hidden field. I found the code online to this, but when I added multiple fields to the form, autocomplete worked by changing the reference from ID to a CLASS. But the hidden fields did not.

I believe the issue is that I need to have the specific ID tag name to update the value for the specific hidden field. I was thinking I could do something like get the ID of the current field that is being updated with the autocomplete...that is where I need some help.

Code:
$().ready(function() {

    $(".course").autocomplete("get_course_list2.php", {
            width: 360,
            matchContains: true,
            mustMatch: true,
            //minChars: 0,
            //multiple: true,
            //highlight: false,
            //multipleSeparator: ",",
            selectFirst: false
    });

    $(".course").result(function(event, data, formatted) {
            $("#course_val").val(data[1]);
    });
});
Here is the HTML form

Code:
<form autocomplete="off">
    <p>
        Course Name <label>:</label>
        <input type="text" name="course1" class="course" id="course1" />
        <input type="hidden" name="course_val1" class=".course_val" id="course_val1" />
    </p>
    <p>
        Course Name <label>:</label>
        <input type="text" name="course2" class="course" id="course2" />
        <input type="hidden" name="course_val2" class=".course_val" id="course_val2 " />
    </p>
    <input type="submit" value="Submit" />
</form>
I would appreciate any help provided.

Thanks
jlimited
jlimited is offline   Reply With Quote
Old 10-18-2012, 05:00 AM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
if everything else works then you should be able to do this:

Code:
$(".course").result(function(event, data, formatted) {
            $( "#"+$(this).attr("id").replace("course","course_val" )).val(data[1]);
    });
provided you get rid of the extra space after the 2 here:
id="course_val2 " />
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
jlimited (10-19-2012)
Old 10-19-2012, 12:15 AM   PM User | #3
jlimited
New Coder

 
Join Date: Sep 2006
Posts: 32
Thanks: 5
Thanked 0 Times in 0 Posts
jlimited is an unknown quantity at this point
Works beautifully...thanks.

jlimited
jlimited is offline   Reply With Quote
Reply

Bookmarks

Tags
autocomplete, jquery

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 04:41 PM.


Advertisement
Log in to turn off these ads.