开发者

how to populate select box using jquery in spring forms

开发者 https://www.devze.com 2023-03-10 21:16 出处:网络
I return a map to the post method, which is correctly displayed in alert function. How do I append the values of the map to the select option with id course?

I return a map to the post method, which is correctly displayed in alert function. How do I append the values of the map to the select option with id course?

<script type="text/javascript" >
$(document).ready(function(){
      $("select#dept").change(function(){
          alert("inside jquery1");
        $.post("getCourses.htm",{depName: $(this).val()}, function(j){
            $.each(j, function(key, value) { 
                  alert(key + ': ' + value); 
                    }); 
        });
      });
    });
</script>
</head>
<body>
<h6>Set Course Fee</h6>
<form:form method="POST" commandName="courseFee">
<table cellspacing="7">
    <tr>
        <td>Department:</td>
        <td><form:select path="pk.dept" id="dept">
            <form:option value="select" label="select"/>
            <form:options items="${deptList}"/> 
        </form:select></td>
    开发者_如何学运维</tr>

    <tr>
        <td>Course:</td>
        <td><form:select path="pk.course" id="course">
        </form:select></td>
    </tr>
    <tr>
        <td><input type="submit" value="Save" ></td>
    </tr>
</table>
</form:form>


I would try this:

$.post("getCourses.htm",{depName: $(this).val()}, function(j){
  var opts = '';
  $.each(j, function(key, value) { 
    opts += '<option value="'+value+'">'+key+'</option>';
  }); 
  $('#course').html(opts);
});
0

精彩评论

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