0

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>
1
  • How is the variable j formatted? Commented Jun 6, 2011 at 7:14

1 Answer 1

1

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);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.