Topic: Copying a value from a collection_select with javascript?

I'm quite new at Ruby on rail and an issue with a view is driving me crazy... In facts, I'm trying to get a value from a select box (collection_select) and copy it into another field of the form. It's working like a charm when I use the code with a simple textfield like:

<%= f.text_field :compte, :onchange => "copyCredit()"%>

but nothing the copy does not work when I change for a collection_select like this:

<%= f.collection_select(:compte, @compte, :compte, :nom, :onchange => "copyCredit()") %>

Here is the Javascript code:

<script type = "text/javascript">
function copyCredit() {
    var x = document.getElementById("entree_compte").value;
    document.getElementById("journal_lignes_attributes_1_compte").value = x;

What's wrong with it?

Is there someone  who could help me to find the right syntax?

Thanks a lot.

Last edited by dannoel (2011-09-09 13:58:48)