Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get values of multiple selected ids
    text
    copied!<p>If i have the bookd_ids and book_titles as follows in the database:</p> <pre><code>id | title --------------- 1 | abc 2 | xyz 3 | pqr </code></pre> <p>The view is shown below::</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;%= select("books", "book_id", Book.all.collect {|b| [ b.title, b.id ] },{:include_blank =&gt; false})%&gt; &lt;/td&gt; &lt;td&gt; &lt;img src="/images/add_icon.png" alt="Add Book" width="20px" height="20px" onclick="AddBook()" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td id="current"&gt; &lt;br /&gt; Current Books&lt;br /&gt; &lt;p id="none" style="font-style: italic; font-weight: lighter"&gt; None Selected&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td id="tdbook"&gt;&lt;/td&gt; &lt;td id="tdbookimg"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>When i click on the add_icon.png image, it adds the selected book under selectedbooks header. If i do it multiple times it add multiple selected rows under selected books. </p> <p>the AddBook() function is written as:</p> <pre><code>function AddBook(){ count = count + 1; $('#none').hide(); var id = $("#books_book_id").val(); $("#tdbook").append("&lt;p id='row" + id + "'&gt;&lt;label for='txt" + id + "'&gt;" +$("#books_book_id option:selected").text() + "&lt;/label&gt;&lt;/p&gt;"); $("#tdbookimg").append("&lt;p id='rowimg" + id + "'&gt;&lt;/p&gt;"); } </code></pre> <p>i can get the id of one book thru jquery this way:</p> <p>var id = $("#books_book_id").val();</p> <p>How to get multiple ids when multiple items are added. So that i can get the values in the controller.</p> <p>Thanks, Kumar</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload