# Quoting using JS in Rails 2

**URL:** <https://www.ruby-forum.com/t/quoting-using-js-in-rails-2/129115>\
**Category:** Rails\
**Created:** [February 14, 2008, 3:20pm UTC](https://www.ruby-forum.com/t/quoting-using-js-in-rails-2/129115 "2008-02-14T15:20:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Redrum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5e9695/32.png) [@Redrum](https://www.ruby-forum.com/u/Redrum)\
**Post date:** [February 14, 2008, 3:20pm UTC](https://www.ruby-forum.com/t/quoting-using-js-in-rails-2/129115/1 "2008-02-14T15:20:18Z")

</div>

Hello all,  
I’m looking for a good solution to provide “smart quoting” for an app  
I’m making. The end-user workflow I’m hoping to accomplish is this:

- User reads entry, ie a blog post or a news article

- User highlights a passage in the entry in his browser

- User clicks a link in the page and a form appears. The form’s text  
area should contain the highlighted text. (This is one step I’m unsure  
of how to accomplish. So far all I’ve found is JS to copy a pre-  
selected passage that is already wrapped in a DIV.)

- The user submits the form, eventually via AJAX, and is returned to  
the entry. The entry model would has\_many :quotes, or :comments, or  
whatever fits the context naming-wise. That form would add a new one  
to the entry. The quote model would validate against the parent entry  
to ensure that the content of the quote is actually contained within  
the body of the entry.

- Additionally, I’m hoping to make a link next to each quote clickable  
that will then use JS to find the passage within the entry’s body, and  
wrap it in a DIV to highlight the text in a new color, background, and  
space it off from the rest of the entry. (This is something else I’m  
unsure of, but I think I’ll find it easy enough to figure out on my  
own.)

Any thoughts? Again, I’ve looked briefly for javascript to interact  
with copying/pasting, but the main point I’m stuck on is just getting  
what the user has highlighted.

Thanks for your time,  
Shane Sveller

---

<div class="post-metadata">

**Author:** ![Redrum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5e9695/32.png) [@Redrum](https://www.ruby-forum.com/u/Redrum)\
**Post date:** [February 14, 2008, 4:54pm UTC](https://www.ruby-forum.com/t/quoting-using-js-in-rails-2/129115/2 "2008-02-14T16:54:00Z")

</div>

> Any thoughts? Again, I’ve looked briefly for javascript to interact  
> with copying/pasting, but the main point I’m stuck on is just getting  
> what the user has highlighted.

any help?  
[http://www.google.com/search?hl=en&q=javascript+highlighted+text&btnG=Search](http://www.google.com/search?hl=en&q=javascript+highlighted+text&btnG=Search)

---

<div class="post-metadata">

**Author:** ![Redrum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5e9695/32.png) [@Redrum](https://www.ruby-forum.com/u/Redrum)\
**Post date:** [February 14, 2008, 6:03pm UTC](https://www.ruby-forum.com/t/quoting-using-js-in-rails-2/129115/3 "2008-02-14T18:03:36Z")

</div>

Thanks, that’s a great start. I guess my google-fu is weak today.
