I want to add a simple onChange event to a select list I have in Rails. How do I do this?
This is the select box code:
= f.select(:question_type_id, QuestionType.all.collect {|qt| [ qt.name, qt.id ]}, { :include_blank => "Please Select a Question Type" })
The onChange event is supposed to call a function, fillAnswerNumber(), which takes the currently selected value and adds a bunch of options to another select list based on the result.
edit: I realised that i needed an onChange event actually…
I think I figured it out… thanks to some SO answers and a couple of handy blog posts.
Here’s what I’ve got. My select looks like this:
and my JavaScript (JQuery) code looks like this: