I am using rails 4 and ruby 2. I want to pass a value in the check_box. If I checked it, then it should take value =3 else "select_MedicalCenter" will be displayed and :medical_center_id can be selected from there. I did this and its not working.
<div id ="display_box" >
<%= f.label :assoiated_to_none %>
<%= f.check_box :medical_center_id, { checked: true },'3',:onchange=>"$('#select_MedicalCenter').show();"%>
</div>
<div id="select_MedicalCenter" style="display:none;"><%= f.label :medical_center %><br />
<%= f.collection_select :medical_center_id,MedicalCenter.all,:id,:name,:prompt=>true%>
</div>
I found the answer. I added a javascript code.
$("input:checkbox[name='user[medical_center_id]']").change(function(){
if(this.checked){
this.value=3;
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.