Topic: I have to copy a form field value into another dinamically...

I have a form with various fields. I now need to copy a input field value (as soon as the user enter some text in it) into other two fields of the same form. How can i do that?

Re: I have to copy a form field value into another dinamically...

Use JavaScript to set up an onchange event in the input field and set the values.

If you are using prototype, you can use $F('id') to get the value of the form field identified by 'id'.

Toby Hede
===================================================
FiniteStateMachine - Software Development for Social Networks
===================================================

Re: I have to copy a form field value into another dinamically...

tobyhede wrote:

Use JavaScript to set up an onchange event in the input field and set the values.

If you are using prototype, you can use $F('id') to get the value of the form field identified by 'id'.

can you describe how to do this specifically with rails and rails prototype helpers 'cause i'm not so expert in pure javascript?

Re: I have to copy a form field value into another dinamically...

ok i've tried to put this as a parameter to my form field helper and works perfectly:

:onchange => 'customer_presso_fatt.value = customer_rag_soc.value; customer_presso_merce.value = customer_rag_soc.value'

...except for the fact that when i put a value in my "main" form field that i've already used in the past in that very field (and that value is remained in the list of values in that field window that appears when i click on a form field), that value isn't copied to the secondary fields and that is strange! Why would javascript do that?

Last edited by skyblaze (2007-09-05 09:20:01)