javascript - Setting a variable when user selects from a dropdown -


in rails view, have dropdown menu of patients. when user selects patient, want set @patient patient.find(id) id data attribute on item user selected.

how can achieve this?

action:

 def options     @assessment = current_user.assessments.new     @patients = current_user.patients.sort_by{|e| e.first_name.downcase}     @patient = current_user.patients.new     @templates = template.all   end 

view:

<%= form_for @assessment, :method=>"get", :url => url_for(:action => 'new') |f| %>      <%= f.select :patient_id, content_tag(:option,'select patient...',:value=>"")+content_tag(:option,'new patient',:value=>"")+options_from_collection_for_select(@patients, 'id', 'full_name'), :class=>"form-control" %>   <%= f.hidden_field :user_id, :value => current_user.id %>      <div class="row" id="assessment-type" style="display:none;">       // want set @patient here whatever user selected in above select tag //       <% if @patient.has_past_assessments? %>       <%= link_to "new injury", templates_path, :id=>"new-injury", :remote=> true %> or <%= link_to "followup assessment", "#" %>     <% end %>     <%= f.hidden_field :template_id %>   <% end %>  </div>  <script>    $(function(){     $('#assessment_patient_id').chosen({width: "100%"});   });    $('#assessment_patient_id').change(function(){     var e = document.getelementbyid("assessment_patient_id");     var patient_id = (e.options[e.selectedindex].value)      if (patient_id == 0) {       window.location.href = "/patients/new"     } else {       $('#assessment-type').slidedown(350);     }      $('#assessment-type').find('.template').on('click', function(){       startspinner()       var templateid = parseint($(this).find('a').attr("id"));       $('#assessment-type').find('.template').removeclass('active');       $(this).addclass('active');       $('#assessment_template_id').val(templateid);       $('.new_assessment').submit();     });     });    </script> 


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -