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; } }
- you forgot
$
, there noselectpicker
selector, have use class or id.selectpicker
or#selectpicker
when use jquery (depends on html). - there no
disable
, have usedisabled
, can't use quotation markstrue
,false
. - you can't use
.change(function changetextbox())
, use$(document).on('change', '#selectpicker', changetextbox)
. 0
must in quotation marks.- i assume textarea disabled (not hidden css).
Comments
Post a Comment