fill form when collection_select is changed

E

Edgars Liepa

Hey there. :)
I have a problem.
I have collection_select, witch takes values from DB
I need to run fill textboxes from other table in DB, when
collection_select is selected.. can anyone tell me how can i make this
run function when collection_select is changed, cos my code is not
working..
And i have jquery in my ruby on rails project, so thats ok..

my code:

<script type="text/javascript">

function fill_form(a)
$.getJSON('/sticks/' + a.id + '.json', function(data) {
var items = [];

$.each(data, function(key, val) {
alert(key + ': ' + val)
};
*/
}
}
</script>
<%= f.label :stick_type %>
<%= h.collection_select :stick_id, Stick.all, :id, :stick_type,
:prompt => "Select Stick", :eek:nchange => "fill_form(this)" %>
<br />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top