how to programmatically select an option in jquery ui autocomplete

Discussion in 'Javascript' started by Generale Cluster, May 31, 2010.

  1. Hello, I have a jquery ui autocomplete widget in a form and I'd like to
    preselect its value from a database.
    My autocomplete works in the following way: the id is a number, the
    label and the value are the same and are a concatenation of id + " - " +
    When a value from the autocomplete is selected, a hidden field's value
    is set to the value of id.
    Then, the hidden field value is saved to the db when the form is
    submitted. When the user comes back on the page for editing, I need to
    reload the value from the db: I set the hidden field value again and
    then I would like to precompile the value of the autocomplete widget
    with the concatenation of id + " - " + description taken form the db.
    I think I should trigger the event of selecting a row in the
    autocomplete, but I don't know how to do. Do you have any ideas? Here is
    the code of the autocomplete:

    source: 'do_contratto.php',
    select: function(event, ui) {

    then I'm able to open the autocomplete with


    I'm missing how I can iterate the list of found options and select the
    appropriate one according to the value of the "id" property.

    Thank you
    Generale Cluster, May 31, 2010
    1. Advertisements

  2. Generale Cluster

    Frobernik Guest

    Frobernik, May 31, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.