Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating textarea with selected item from dropdown in a template using knockoutjs
    primarykey
    data
    text
    <p>I'm using a knockout template while iterating through a list of cart objects. In the template I populate a dropdown with all of the products using the Name as the option text and option value. I want a corresponding text area to populate with the product description which is a property on the object that the dropdown list is bound to. Is there a knockout way of doing this or do I need to use jQuery? Thanks for the help.</p> <pre><code>&lt;script type="text/html" id="edit-template"&gt; &lt;div class="row edit"&gt; &lt;div class="span3"&gt; &lt;select data-bind=" options: $root.products, optionsText: 'Name', optionsValue: 'Name', value: Name, optionsCaption: 'Select a Product'"&gt;&lt;/select&gt; &lt;/div&gt; &lt;div class="span4"&gt; &lt;!-- This is where I'm not sure what I need to do for this text area --&gt; &lt;textarea class="span4" rows="3" data-bind="value: Description"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;div class="span1"&gt; &lt;button class="btn btn-primary" style="margin-top:20px;" data-bind="click: $root.save"&gt;Save&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/script&gt; </code></pre> <p><strong>UPDATE</strong> Here is a <a href="http://jsfiddle.net/dmase05/trr5e/1/" rel="nofollow">fiddle</a>. In this case I'd like to see the textbox updated with the name and the text area updated with the description. So full disclosure, my app actually has nothing to do with a shopping cart, but I tried to simplify this SO question to a shopping cart example so that readers don't have to understand business domain knowledge of the app.</p> <p><strong>UPDATE 2</strong> Made minor change to the fiddle</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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