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?
- Fill out the url field
- When text field is out of focus do:
- Find Store with matching url
- Set that store as default
Any help would be much appreciated!
basic gist:
http://jsfiddle.net/sScma/2/