javascript - Toggle element on selection from dropdown menu in Bootstrap 3.0 -


i'm using bootstrap 3.0 ruby on rails 4.2.5, , need make in form when user selects option "no" drop down menu, next text field shown them, otherwise, text field remains hidden. i've found similar question solution, couldn't implement bootstrap form, attempt @ :

dropdown input: <%= f.select :answer, [["yes", 1], ["no", 0]], label: "do wish bla bla? ", class: "selectpicker", id: "selectpicker" %>

toggled input (should show when "no" picked) :
<%= f.text_area :explain , label: "please explain why not", id: "sdd"%>

javascript: `

 ("selectpicker").change(function changetextbox());  function changetextbox() {     if (document.getelementbyid("selectpicker").value === 0 ) {         document.getelementbyid("sdd").disable='true';     } else {         document.getelementbyid("sdd").disable='false';     } } 

`

i tried changing value === 0 value == 0 , 0 no, still doesn't work.

they're in code in order, i'm not sure how should work bootstrap form tags. in advance.

reference : question got code enable/disable of textbox on option selected drop down menu

$(document).on('change', '#selectpicker', changetextbox);  function changetextbox() {   if (document.getelementbyid("selectpicker").value === '0') {     document.getelementbyid("sdd").disabled = true;   } else {     document.getelementbyid("sdd").disabled = false;   } } 
  1. you forgot $ , there no selectpicker selector, have use class or id .selectpicker or #selectpicker when use jquery (depends on html).
  2. there no disable, have use disabled , can't use quotation marks true , false.
  3. you can't use .change(function changetextbox()), use $(document).on('change', '#selectpicker', changetextbox).
  4. 0 must in quotation marks.
  5. i assume textarea disabled (not hidden css).

codepen example


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -