This could help:
Demo - http://jsfiddle.net/nmvf6/1/
This would give you the option with text
B and not the ones which has text that contains B . Hope this helps
EDIT:
For recent versions of jQuery the above does not work. As commented by Quandary below, this is what works for jQuery 1.9.1:
|
jQuery( document ).ready(function() { var company_type = $("#user_company_type").val();// Option text val var user_type_id = $('#user_user_type_id option').filter(function () {
return $(this).html() == company_type }).val() document.getElementById('user_user_type_id').value = user_type_id; });
RAILS SELECT TAG WITH FORM OR WITHOUT FORM
= select_tag 'user_types_ids[]',options_for_select(
UserType.all.map {|data| [data.name, data.id]},@selected_user_types),
{:multiple => :multiple,:id=>"user_types_ids"} = f.select :knowledge_base_category_id, options_for_select(KnowledgeBaseCategory.all.map {|data| [data.name, data.id]},@article.knowledge_ base_category_id)