开发者

How to set default selection for combo box?

I am using .tmpl() to fill out templates like so

<script type="text/x-jquery-tmpl" id="template">
  <form action="" method="post">
    <div>
      <div> ${ID} </div>
      <div> <input name="title" id="${ID}_title" value="${title}" type="text" /> </div>
      <label> Section (${section}) </label> &nbsp;
      <select name="section" id="${ID}_section">
        <option value="">-- Select --</option>
        <option value="aaa">AAA</option>
        <option value="bbb">BBB</option>
      </select>
    </div>
  </form>
</script>

where ${section} wil contain either the开发者_如何学编程 combo box value aaa or bbb.

How do I set the default selection for the combo box according to ${section}?


try something like:

<select name="section" id="${ID}_section">
    <option value="">-- Select --</option>
    <option value="aaa" {{if $section == 'aaa'}} selected="selected" {{/if}}>AAA</option>
    <option value="bbb" {{if $section == 'bbb'}} selected="selected" {{/if}}>BBB</option>
</select>  

Update
Well my jsfiddle in comment was just a way to simulate your setup, because you don't attached it in this post. If $section == bbb or aaa try this:

 <select name="section" id="${ID}_section">
    <option value="">-- Select --</option>
    <option value="aaa" {{if section == 'aaa'}} selected="selected" {{/if}}>AAA</option>
    <option value="bbb" {{if section == 'bbb'}} selected="selected" {{/if}}>BBB</option>
</select>

Otherwise more code is needed, how do you call your template and how is $section assigned.

Update 2
try: http://jsfiddle.net/3TrEY/6/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜