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

  • Home
  • SEARCH
  • 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 8240187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:24:10+00:00 2026-06-07T20:24:10+00:00

Using: Rails and jQuery I have a form with a Url textbox input in

  • 0

Using: Rails and jQuery

I have a form with a Url textbox input in which a user can put a url such as:

http://www.webshop.com/article/123

url is an attribute of @product.

In the same form I also have a dropdown populated with stores (Store.all). The store has an attribute store.short_url that could be “www.webshop.com”.

I want to use jQuery so that when a user types in http://www.webshop.com/article/123 in the url-textbox I want to compare that with the Store objects and see if that store is in the database which short_url matches the domain name and if so, default that Store in the dropdown.

The string matching should not be a problem but how do I handle this in jQuery?

  1. Fill out the url field
  2. When text field is out of focus do:
  3. Find Store with matching url
  4. Set that store as default

Any help would be much appreciated!

  • 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-07T20:24:12+00:00Added an answer on June 7, 2026 at 8:24 pm

    basic gist:

    $(document).ready(function(){
        $('#url_input').change(function(){
        var urlPattern = /(http|ftp|https):\/\/([\w-]+(\.[\w-]+)+)([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/
            if(urlPattern.test($(this).val())){
                alert('hurray');
                url = ($(this).val().match(urlPattern))[2].toLowerCase();
                $('option[value="'+url+'"]','#available_types').each(function(){$(this).attr('selected',true)});
            }
        });
        });
        ​
    

    http://jsfiddle.net/sScma/2/

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

Sidebar

Related Questions

I have started using jQuery and rails. I have made a simple form that
I am using the jQuery Form Plugin with my Rails app. I have a
I'm using Rails 2.3.8 and have a jQuery AJAX form using posted using: jQuery.fn.submitWithAjax
I'm using Rails 3.2.3 and I have the following form <%= form_for(@item, url: list_path,
Using Ruby 1.8.7-p358, Rails 3.0.12, gem responder, gem simple-form; jquery_ujs.js I have a form
I'm using jQuery with rails and have the following piece of code $('#related').html(<%= render
I am using jQuery with rails. I am trying to make a PUT request
I am using jquery-rails-autocomplete and want to have autocomplete on more than one column.
I have jquery working on my Rails app using the gem 'jquery-rails' . I
This is a Rails 3 project using jQuery 1.4.4. I have an index action

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.