Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery.tmpl and <select> options
    text
    copied!<p>I'm using the jQuery Template plugin (jquery.tmpl.js) and for the most part I understand it, but I'm really struggling to get it to work with elements where the options for the select element come from one JSON object but the selected value comes from the property of another. Below is my code:</p> <p>The HTML:</p> <pre><code> &lt;fieldset id="userFieldset"&gt; &lt;script id="userTemplate" type="text/x-jquery-tmpl"&gt; &lt;label for="TitleId"&gt;Title&lt;/label&gt; &lt;select value="${TitleId}" id="TitleId" name="TitleId"&gt; {{tmpl(titles) "#titleTemplate"}} &lt;/select&gt; &lt;label for="UserName"&gt;Name&lt;/label&gt; &lt;input type="text" name="UserName" id="UserName" class="text ui-widget-content ui-corner-all" value="${UserName}"/&gt; &lt;label for="Password"&gt;Password&lt;/label&gt; &lt;input type="password" name="Password" id="Password" class="text ui-widget-content ui-corner-all" value="${Password}"/&gt; &lt;/script&gt; &lt;script id="titleTemplate" type="text/x-jquery-tmpl"&gt; &lt;option value="${ID}"&gt;${Value}&lt;/option&gt; &lt;/script&gt; &lt;/fieldset&gt; </code></pre> <p>The javascript:</p> <pre><code>var titles = Sys.Serialization.JavaScriptSerializer.deserialize("[{\"ID\":3,\"Value\":\"Mr\"}, {\"ID\":2,\"Value\":\"Ms\"}, {\"ID\":1,\"Value\":\"Doctor\"}]", false); function showEditUser(user) { $("#userFieldset").empty(); $("#userTemplate").tmpl(user).appendTo("#userFieldset"); $("#userDialog").dialog("open"); } </code></pre> <p>However, this doesn't change the selected value of the TitleId select. Any help would be greatly appreciated.</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