0

I have a select field in a form in views/touches/new:

<%= f.select :touch_type, options_for_select(['Attack', 
'Block','Pass', 'Set']), {include_blank: "Select touch type..."
:onchange => 'populate()'}, class: "form-control" %>

I'm trying to call the function "populate" in assets/javascripts/touches.js.coffee

jQuery ->
  populate = ->
    s1 = $('#touch_touch_type_id').html()
    s2 = $('#touch_touch_result_id').html()
    s2.html = ""

    if s1.value == "attack"
      optionArray = ["score|Score", "out|Out"]

    for option in optionArray
      pair = optionArray[option].split "|" 
      newOption = document.createElement "option"
      newOption.value = pair[0]
      newOption.html = pair[1]
      s2.options.add newOption

...so that it will populate this select field with options specific to the choice made in the first select field shown here:

<%= f.select :touch_result, {}, {include_blank: 
"Select touch result..."}, class: "form-control" %>

When I change the option in the first select field, nothing happens. I tried a test method called "yell()" to see if it called that but still no luck.

yell = ->
    alert "TEST"

Not entirely sure where my error lies.

Any help is appreciated.

kzjasta
  • 3
  • 3

0 Answers0