# Data exists in table? Checkbox Problem

**URL:** <https://www.ruby-forum.com/t/data-exists-in-table-checkbox-problem/171668>\
**Category:** Rails\
**Created:** [July 7, 2009, 12:20pm UTC](https://www.ruby-forum.com/t/data-exists-in-table-checkbox-problem/171668 "2009-07-07T12:20:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [July 7, 2009, 12:20pm UTC](https://www.ruby-forum.com/t/data-exists-in-table-checkbox-problem/171668/1 "2009-07-07T12:20:19Z")

</div>

Hi,

I want to add a tag-search to my page. The tags can be given to each  
item by clicking a checkbox. The value of the checkboxes is saved in the  
table using the check\_box\_tag.  
By editing the tags of an item (refreshing the page) the checkboxes  
delete their status - reset theirselves.

Question:  
How can I check if a box was clicked last time(value saved in the table)

into the blue:  
if “value” exists in “table”  
document.getElementById(“checkbox1”).checked = true  
if “value” doesn’t exist in “table”  
document.getElementById(“checkbox1”).checked = false

Thx for your answers

---

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [July 7, 2009, 4:35pm UTC](https://www.ruby-forum.com/t/data-exists-in-table-checkbox-problem/171668/2 "2009-07-07T16:35:55Z")

</div>

Not even one response?

---

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [July 7, 2009, 5:32pm UTC](https://www.ruby-forum.com/t/data-exists-in-table-checkbox-problem/171668/3 "2009-07-07T17:32:20Z")

</div>

Hans H. wrote:  
[…]

> Question:  
> How can I check if a box was clicked last time(value saved in the table)

Look at the appropriate field in the database. If you use form\_for, it  
does that for free.

> into the blue:  
> if “value” exists in “table”  
> document.getElementById(“checkbox1”).checked = true  
> if “value” doesn’t exist in “table”  
> document.getElementById(“checkbox1”).checked = false

Why on earth would you do this in client-side JavaScript instead of on  
the server side? That doesn’t appear to make sense.

> Thx for your answers

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [July 7, 2009, 5:25pm UTC](https://www.ruby-forum.com/t/data-exists-in-table-checkbox-problem/171668/4 "2009-07-07T17:25:07Z")

</div>

It is not quite clear what you are trying to do. But it seems like you  
are reinventing a square wheel 🙂  
Did you try some ready solutions like

> **[GitHub - mbleigh/acts-as-taggable-on: A tagging plugin for Rails applications...](https://github.com/mbleigh/acts-as-taggable-on/)**
>
> A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts. - GitHub - mbleigh/acts-as-taggable-on: A tagging plugin for Rails applications that allows for custom...

?

Regards

–  
Vitaly Kushner  
[http://twitter.com/vkushner](http://twitter.com/vkushner)  
Founder, Astrails Ltd. [http://astrails.com](http://astrails.com)  
Check out our blog: [http://blog.astrails.com](http://blog.astrails.com)

On Jul 7, 1:20 pm, Hans H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [July 7, 2009, 7:56pm UTC](https://www.ruby-forum.com/t/data-exists-in-table-checkbox-problem/171668/5 "2009-07-07T19:56:40Z")

</div>

Hans H. wrote:

> I tried and tried and tried

And what did you try?

> … but everything in my checkbox is deleted  
> after refreshing the page (instead of the values in my database) so how  
> can I ask for them.

The behavior of unsubmitted forms in the browser on page refresh is  
somewhat browser-dependent, but most browsers will reset them. This is  
what users expect.

Why do you need this functionality, anyway? If you explain what you’re  
trying to achieve by doing this, perhaps we can be of more help.

> Thx till now…

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [July 7, 2009, 5:36pm UTC](https://www.ruby-forum.com/t/data-exists-in-table-checkbox-problem/171668/6 "2009-07-07T17:36:10Z")

</div>

I tried and tried and tried … but everything in my checkbox is deleted  
after refreshing the page (instead of the values in my database) so how  
can I ask for them.

Thx till now…
