Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    32
    Thanks
    5
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,876
    Thanks
    56
    Thanked 536 Times in 533 Posts
    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 " />

  • Users who have thanked xelawho for this post:

    jlimited (10-19-2012)

  • #3
    New Coder
    Join Date
    Sep 2006
    Posts
    32
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Works beautifully...thanks.

    jlimited


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •