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

Let's say I have this form and script: <SCRIPT LANGUAGE=JavaScript> function handleSubmit() { return
I have this form: <form name=customize> Only show results within <select name=distance id=slct_distance> <option>25</option>
I have this form submit code: Event.observe(window, 'load', init, false); function init() { Event.observe('addressForm',
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
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 form: <form action=contact.php method=post id=contactform> <ol> <li> <label for=name>First Name *
I have this form with a JS function to verify that there are no
Let's say I have this form: <form action=submit method=post> <select name=category id=categorylist> <option value=love>Love</option>
I have this form in my HTML: <form action=/awe/ChangeTheme/Change method=post> <select id=themes name=themes> ...
I have this form : <form method='GET' name='search' action='index.php?explore=search'> <input type=hidden name=searchType value=all />

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.