State Country Combo filling through JQuery Ajax

Below Servlet Method is called

private String getState(short countryId) {
        String str = "";
        CommonService commonService = (CommonService) AppContext.getSpringBean("CommonService");
        List<TblStateMaster> list = commonService.getState(countryId);
        for (TblStateMaster tblStateMaster : list) {
            str += "<option value='" + tblStateMaster.getStateId() + "'>" + tblStateMaster.getStateName() + "</option>";
        }
        return str;
    }

JQuery Code for filling State Combo on onchange event of Country Combo

<script type="text/javascript" src="resources/js/jQuery/jquery-1.4.3.min.js"></script>
<script type="text/javascript" >
$(function() {
                $('#cmbRegCountry').change(function() {
                    $.post("<%=request.getContextPath()%>/ComboServlet", {objectId:$('#cmbRegCountry').val(),funName:'stateComboValue'},  function(j){
                        $("select#cmbRegState").html(j);                        
                    });
                });
            });
</script>
Advertisements
This entry was posted in JQuery, Servlet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s