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 7873475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:31:31+00:00 2026-06-03T02:31:31+00:00

I have implemented a simple search on my website, the idea is choose what

  • 0

I have implemented a simple search on my website, the idea is “choose what field you want to search on, then input your search query.” However, at least one of the search options should be limited to a dropdown menu instead of having the freedom of a text field.

I have been reading and testing some options, saw a couple posts about :on_change and some in-depth javascript solutions, but I just haven’t been able to see what to do.

My current view has a select_tag followed by a text_field_tag, but I want to check what value the select_tag is on and use that to decide whether the next field is a text_field_tag or a select_tag. I am using Haml, this is in my view:

#simple-search-options
  =form_tag packages_path, :method=>'get' do
    Search by:
    = select_tag :search_option, options_for_select(@search_options, @option)
    = text_field_tag :search_string, @s_string
    = submit_tag 'Search'

Note that I am setting default values for the select_tag and the text_field_tag with whatever values were entered in the previous search, thats where the variables @option and @s_string are coming from. This possibly complicates the solution because it means that when the page is first generated, I would like to have already made the choice of what to display based on the value of @option.

I was hoping to stick a div between the first select_tag and the submit_tag that would get populated by some controller and some view, but I didn’t know how to follow through.

  • 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-06-03T02:31:33+00:00Added an answer on June 3, 2026 at 2:31 am

    You should add both select_tag and text_field_tag in your template, then hide and show them using JavaScript. It’s better to set different names for this two fields because their types are different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple rails search implemented in my app. At the time I
I have implemented a simple search functionality for my rails 3 blog application. I
I have developed a simple contacts application and also implemented search using name. But
I have implemented a search engine in C for my html website. My entire
I have implemented a simple search function that highlights a row in a DataGrid
In our desktop application, we have implemented a simple search engine using an inverted
I have implemented a simple entity ejb with a @version annotation. I expect that
I have implemented a simple linux shell in c. Now, I am adding some
I have implemented a simple RSS reader in Java. I hit a URL and
I have implemented my own simple version of a navigation window, mainly because navigation

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.