# Update multiple fields with onclick

**URL:** <https://www.ruby-forum.com/t/update-multiple-fields-with-onclick/191051>\
**Category:** Rails\
**Created:** [July 3, 2010, 12:13pm UTC](https://www.ruby-forum.com/t/update-multiple-fields-with-onclick/191051 "2010-07-03T12:13:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![InventoryTrackers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/59ef9b/32.png) [@InventoryTrackers](https://www.ruby-forum.com/u/InventoryTrackers)\
**Post date:** [July 3, 2010, 12:13pm UTC](https://www.ruby-forum.com/t/update-multiple-fields-with-onclick/191051/1 "2010-07-03T12:13:02Z")

</div>

We’ve all seen the checkout forms with Bill To: and Ship To: I’d like  
to have a button that says “Ship to Bill To:” and if we click it, it  
copies all the Ship To: fields across such as phone, email, etc.  
I’ve been looking at link\_to\_function, is that the right path?  
I’ve done observe\_fields before but that went to a controller action  
whereas here we could get by just copying params[field\_values].  
Thanks,  
David

---

<div class="post-metadata">

**Author:** ![InventoryTrackers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/59ef9b/32.png) [@InventoryTrackers](https://www.ruby-forum.com/u/InventoryTrackers)\
**Post date:** [July 3, 2010, 4:12pm UTC](https://www.ruby-forum.com/t/update-multiple-fields-with-onclick/191051/2 "2010-07-03T16:12:30Z")

</div>

InventoryTrackers wrote:

> We’ve all seen the checkout forms with Bill To: and Ship To: I’d like  
> to have a button that says “Ship to Bill To:” and if we click it, it  
> copies all the Ship To: fields across such as phone, email, etc.  
> I’ve been looking at link\_to\_function, is that the right path?

Probably. The JavaScript for this should be very simple to write. If I  
were you, though, I wouldn’t use link\_to\_function unless you’re already  
on Rails 3: Rails 2’s JS helpers mix JS into your HTML, where it really  
doesn’t belong.

> I’ve done observe\_fields before but that went to a controller action  
> whereas here we could get by just copying params[field\_values].  
> Thanks,  
> David

---

<div class="post-metadata">

**Author:** ![InventoryTrackers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/59ef9b/32.png) [@InventoryTrackers](https://www.ruby-forum.com/u/InventoryTrackers)\
**Post date:** [July 3, 2010, 5:16pm UTC](https://www.ruby-forum.com/t/update-multiple-fields-with-onclick/191051/3 "2010-07-03T17:16:15Z")

</div>

Probably a whole lot easier if you just have a checkbox indicating if  
the ship is the same as the bill\_to. Pretty common to do that less  
hassle.
