0

I am wanting to use Javascript to insert values into an option_to_select for rails.

My Javascript function is not doing it. Here it is.

function populateGlobalDonorClaimPhase() {
    var donor_claim_phase = $('[id^=phase-table-row]').size();
    $('#payer_contract_donor_claim_phase').val(donor_claim_phase);
}

this is able to fill the field when it is f.text_field, but it does nothing with f.select, in other words option_for_select.

  = f.select :donor_claim_phase, options_for_select(@donor_claim_phase, @selected_donor_claim_phase)

How can I correctly insert these values into @donor_claim_phase?

I have @selected_donor_claim defaulted to a value, so that is not the problem. It's just correctly filling @donor_claim_phase values.

lakeIn231
  • 1,177
  • 3
  • 14
  • 34
  • You should add a new option select to the form (insert it into the DOM w/ JS), then make it selected like here: http://stackoverflow.com/questions/1085801/get-selected-value-in-dropdown-list-using-javascript – Sean Magyar Feb 22 '16 at 22:51
  • Can you give an example @SzilardMagyar ? – lakeIn231 Feb 22 '16 at 22:54
  • Here you go: http://stackoverflow.com/questions/8674618/adding-options-to-select-with-javascript So after adding the new option you also have to select it, then you can save the form. – Sean Magyar Feb 22 '16 at 22:56

0 Answers0