How to update fields when checkbox is selected via javascript without going to server?

I’m having a mental block on this.

I’ve got a checkout page form which has ship to and bill to sections.

There’s a checkbox which says ‘bill to same’.

What I’d like to do is fill the bill to fields from the corresponding
ship to fields when the checkbox is selected and turned on.

I don’t want this to be an AJAX request since I’m just copying things
from elements in the DOM.

I assume that I want to use observe_field with the :function option,
but I’m having a hard time thinking through how to do this. I want to
be able to use the prototype helpers to write the function instead of
hand coding javascript.

Any ideas or example code?


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Rick DeNatale [email protected] wrote:

I assume that I want to use observe_field with the :function option,
but I’m having a hard time thinking through how to do this. I want to
be able to use the prototype helpers to write the function instead of
hand coding javascript.

Any ideas or example code?

Rick,

scriptaculous, included with ruby, would make the javascript for
this so simple that you shouldn’t need to bother with protoype helpers,
etc.
I’d imagine it’d be something like:

function copy_fields () {
fields = [ “addr1”, “addr2”, … ]
for(i=0;i<fields.length;i++) {
$(“ship_” + fields[i]).value = $(“bill_” + fields[i]).value
}
}

Cheers,
Tyler