For those with more programming experience than myself, I have a simple question. In Rails, using coffescript, I want to show additional content based on a user's selection. Essentially, if they click on a checkbox, it should reveal an extra field for them to complete; otherwise, it should remain hidden.
Currently, my page renders without any errors, but the div is not initially hidden as expected (I assumed the CSS would handle this) and clicking the checkbox does not trigger any change in state.
Below is my View (_form.html.erb):
<div id="po_state">
<%= f.label :is_holiday %><br>
<%= f.check_box :is_holiday %>
<div id="addStuff">
<div class="field">
<%= f.label :add_stuff %><br>
<%= f.text_area :add_stuff %> </div>
</div>
</div>
Here is my CSS (holidays.css.scss):
#addStuff {
display: none;
}
And my coffeeScript (holidays.js.coffee):
showM = ->
as.style.display = "block"
return
m = document.getElementById("po_state")
as = document.getElementById("addStuff")
m.onclick = showM
I attempted a different approach with my coffeeScript. Unfortunately, no success yet.
$("#po_state").change ->
$("#addStuff").toggle @checked
return