Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6544655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:29:30+00:00 2026-05-25T11:29:30+00:00

I have this in my form, it’s really simple: <script> $(function() { var availableProducts

  • 0

I have this in my form, it’s really simple:

<script>
    $(function() {
        var availableProducts = [
             <% @products.each do |p| %>"<%= p.id %> <%= p.title %> (<%= p.product_type.name %>)",<% end %>
             ""
        ];
        $( "#tags" ).autocomplete({
            source: availableProducts
        });
    });
</script>

That gives me lists of things like 1 Title (Trade Paperback). All rails needs of course, is the id attribute. I’d planned on updating a hidden field with the attribute, using the select: event, but I’m not quite sure how to extract just the id from the data source to update the hidden field with. Should I change the data source to something that can have keys? Like JSON? I still wouldn’t know how to extract from that.

Here’s what the above code looks like in straight html:

<script>
    $(function() {
        var availableProducts = [
              "1 Test Title (eBook)",
              "2 Another Test Title (eBook)",
              ""
        ];
        $( "#products" ).autocomplete({
            source: availableProducts
        });
    });
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:29:30+00:00Added an answer on May 25, 2026 at 11:29 am

    Your source should be an array of {value: , label: } pairs. The labels are what will be displayed and autocompleted on, but then you can store the value in a hidden input.

    Here’s an example:

    http://jsfiddle.net/vZeHr/4/

    and check out this sample on the jquery-ui docs page

    http://jqueryui.com/demos/autocomplete/#custom-data

    To generate the array from rails, you can do something like

    var availableProducts = <%= @products.collect { :label => p.title, :value => p.id }.to_json ->;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this input in a form: <input type=text value=<script src='/js/script.js' type='text/javascript'></script> name=embed/> The
I have this form: <form name=customize> Only show results within <select name=distance id=slct_distance> <option>25</option>
Say I have this simple form: class ContactForm(forms.Form): first_name = forms.CharField(required=True) last_name = forms.CharField(required=True)
I have this little script to toggle a contact form when a button is
In Kohana/CodeIgniter, I can have a URL in this form: http://www.name.tld/controller_name/method_name/parameter_1/parameter_2/parameter_3 ... And then
I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
I have this form: <form name=input action=http://s164074194.onlinehome.us/mail.py method=POST> Username: <input type=text name=email /> <input
i have this form: <form name=myForm action=#> <input type=text name=firstField /> <input type=text name=secondField
i have this form for adding videos. Now, there's a input field for title
I have this form: <form action= method=post> <label for=color>Color:</label> <input type=text style=width: 195px; name=color

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.