# Update a table depending on icon click

**URL:** <https://www.ruby-forum.com/t/update-a-table-depending-on-icon-click/162534>\
**Category:** Rails\
**Created:** [March 11, 2009, 12:33am UTC](https://www.ruby-forum.com/t/update-a-table-depending-on-icon-click/162534 "2009-03-11T00:33:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 11, 2009, 12:33am UTC](https://www.ruby-forum.com/t/update-a-table-depending-on-icon-click/162534/1 "2009-03-11T00:33:32Z")

</div>

Hi,

in a ‘new’ view for a persons model & controller, I want to be able to  
present a number of attribute options in the shape of icons. Each  
click on a different icon should set a given value to an attribute.  
For instance, if the user clicks on the icon for a “girl”, I want the  
‘sex’ attribute to be set to ‘F’ and the ‘girl’ icon to be somehow  
highlighted with a different border…  
When the user is satisfied with the options he set, he clicks on a  
submit button.

I don’t know how to pass the icon clicks as attribute values to my  
controller…

Thanks

---

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 11, 2009, 1:23am UTC](https://www.ruby-forum.com/t/update-a-table-depending-on-icon-click/162534/2 "2009-03-11T01:23:13Z")

</div>

Sacredceltic wrote:

> I don’t know how to pass the icon clicks as attribute values to my  
> controller…

Just create hidden\_field in your form and set it values from javascript  
(onChange)… then submit the form and construct your query with these  
values…

tom

> Thanks

# –

Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

# [www.meinlschmidt.com](http://www.meinlschmidt.com) www.maxwellrender.cz www.lightgems.cz

---

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 11, 2009, 9:22am UTC](https://www.ruby-forum.com/t/update-a-table-depending-on-icon-click/162534/3 "2009-03-11T09:22:09Z")

</div>

Thank you Tom,

but how do you pass the hidden\_field values to the actual record  
attributes from my controller @person = current\_user.person.build()

Say I want to pass the value to @person.sex, for instance ?

---

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 11, 2009, 9:38am UTC](https://www.ruby-forum.com/t/update-a-table-depending-on-icon-click/162534/4 "2009-03-11T09:38:35Z")

</div>

Sacredceltic wrote:

> Thank you Tom,
> 
> but how do you pass the hidden\_field values to the actual record  
> attributes from my controller @person = current\_user.person.build()
> 
> Say I want to pass the value to @person.sex, for instance ?

in the same way as you create other forms…

\<% form\_for(@person) do |f|%\>  
\<%= f.hidden\_field :sex %\>

then on icon you could set onClick=“setSex(‘M’, this)”

function setSex(gender, element) {  
document.getElementById(‘person\_sex’).value=‘M’;  
// change class to make this selected/highlighted  
this.setAttribute(“class”, “highlited”)  
// change other items  
…  
}

other way is to change radio buttons itself to images…  
[http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/](http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/)

> > > When the user is satisfied with the options he set, he clicks on a  
> > > –  
> > > =========================================================================== ====  
> > > Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache
> > 
> > [www.meinlschmidt.com](http://www.meinlschmidt.com) www.maxwellrender.cz www.lightgems.cz  
> > =========================================================================== ====

# –

Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

# [www.meinlschmidt.com](http://www.meinlschmidt.com) www.maxwellrender.cz www.lightgems.cz

---

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 11, 2009, 2:54pm UTC](https://www.ruby-forum.com/t/update-a-table-depending-on-icon-click/162534/5 "2009-03-11T14:54:46Z")

</div>

if you’re not familiar with javascript, then try the image based radio  
buttons, it should be more easier to implement with the standard rails  
way…

tom

Sacredceltic wrote:

> hidden attributes so they are saved along the others when the user
> 
> > in the same way as you create other forms…  
> > // change other items
> > 
> > > On Mar 11, 1:20 am, Tom Z Meinlschmidt [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > > 
> > > > > I don’t know how to pass the icon clicks as attribute values to my  
> > > > > =========================================================================== ====  
> > > > > –  
> > > > > =========================================================================== ====  
> > > > > Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache
> > 
> > [www.meinlschmidt.com](http://www.meinlschmidt.com) www.maxwellrender.cz www.lightgems.cz  
> > =========================================================================== ====

# –

Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

# [www.meinlschmidt.com](http://www.meinlschmidt.com) www.maxwellrender.cz www.lightgems.cz

---

<div class="post-metadata">

**Author:** ![Sacredceltic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sacredceltic](https://www.ruby-forum.com/u/Sacredceltic)\
**Post date:** [March 11, 2009, 2:41pm UTC](https://www.ruby-forum.com/t/update-a-table-depending-on-icon-click/162534/6 "2009-03-11T14:41:48Z")

</div>

Thank you Tom for your help. I understand the logic of modifying a  
hidden field now, but I am afraid there is a connection I still don’t  
make. I am not familiar with javascript.

Where do you place the java function you defined ? In the form  
itself ?  
Is “This” the model class ? Or a div id ?  
I was thinking to use a “link\_to\_remote image\_tag…” but I don’t know  
what it should call. I don’t want to execute any other controller  
action. I want to remain within the “new” action and just set the  
hidden attributes so they are saved along the others when the user  
click on “submit” button of the “new” form.

Thank you
