javascript - Form select option to change what gets rendered -
ruby on rails 4 form drop down selection. if multiple choice selected want render page. if true/false selected want render different page.
i not know why isn't working, javascript knowledge bad:
<h1>new question</h1> <%= form_for(@question) |f| %> <%= render 'shared/error_questions' %> <%= render 'form', f: f %> <%= f.fields_for :answers |builder| %> <div id="mcanswers" style="display:none"> <h1>answers</h1> <%= render 'four_answers', :f => builder %> <%= f.submit "create question", class: "btn btn-lg btn-primary" %> </div> <div id="tfanswers" style="display:none"> <h1>answers</h1> <%= render 'tf_answers', :f => builder %> <%= f.submit "create question", class: "btn btn-lg btn-primary" %> </div> <% end %> <% end %> <hr /> <%= link_to 'back', questions_path %> <script> function checktype() { if ($('#question_question_type').val('mc')) { $('#mcanswers').css('display', 'block'); } else if ($('#question_question_type').val('tf')) { $('#tfanswers').css('display', 'block'); } } $(document).ready(function() { $('select#question_question_type').on('change', function() { checktype(); }); }); </script>
everything rendered beginning. div hiding it. had use controller logic decide when render.
Comments
Post a Comment