Data exists in table? Checkbox Problem

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

Not even one response?

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
[email protected]

It is not quite clear what you are trying to do. But it seems like you
are reinventing a square wheel :slight_smile:
Did you try some ready solutions like
http://github.com/mbleigh/acts-as-taggable-on/
?

Regards


Vitaly Kushner
http://twitter.com/vkushner
Founder, Astrails Ltd. http://astrails.com
Check out our blog: http://blog.astrails.com

On Jul 7, 1:20 pm, Hans H. [email protected]

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
[email protected]

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…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs