Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
heyy....

Iam using ajax jquery to fill a dropdownlist ,The dropdown is fill but when a get the value of dropdownlist from code (ddl.selectedvalue) . I didn't get that value ...



Here is my jquery to fill dropdownlist -

 <script type="text/javascript">
     $(document).ready(function() {

         $("#ctl00_MPPSContent_txtedate").blur(autoFill());
         $("#ctl00_MPPSContent_btnGenereate").click(function() {
             var jno = $("#ctl00_MPPSContent_ddlJournalNo").val();
             if (jno == '-1') {
                 alert('Please Select Journal No');
                 return false;
             }
             else {
                 return true;
             }
         });
     });


     $("#ctl00_MPPSContent_txtedate").blur(function() {

         autoFill();
     });



function autoFill() {
    var fromdate = $("#ctl00_MPPSContent_txtfdate").val();
    var todate = $("#ctl00_MPPSContent_txtedate").val();

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "ReconciliationReportByProduct.aspx/BindJournalNo",
        //  data: "{'txtfromdateDate':'" + txtfromdateDate + "'}",
        data: "{'txtfromDate':'" + fromdate + "','txttoDate':'" + todate + "'}",
        dataType: "json",
        success: function(data) {

            var theHtml = data.d;
            $("#ctl00_MPPSContent_ddlJournalNo").empty();


            $("#ctl00_MPPSContent_ddlJournalNo").append($("<option></option>").val('-1').html('--Select--'));

            if (data.toString().length > 0) {
                $.each(data.d, function(key, value) {

                    $("#ctl00_MPPSContent_ddlJournalNo").append($("<option></option>").val(key).html(value));
                });
            }
        },
        error: function(result) {
            alert('Error');
        }
    });
}


  </script>



Any idea?
Posted

1 solution

As you are adding values on client side you won't be able to get selected value through ddl.selectedvalue as sever is not aware about new values added through Jquery. So in this case you need to fetch value from Request object like below

string seletVal = Request[ddl.UniqueID]
 
Share this answer
 
Comments
aravindnass 27-Oct-13 6:44am    
thankss...Its works....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900