Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
310
Call a java script function from dynamically created dropdowns
posted

RAZOR

@for (int j = 0; j < Model.NoOfProgrammes; j++)
{
<tr style="height: 25px">
<td>@(j + 1)
</td>
<td>
<div>
@Html.Infragistics().ComboFor(model => model.MyProperty[j].EmployeeIDKey).ID("ddlEmployee" + j).DataSource(Model.GetAllUsers).ValueKey("UserIDKey").MultiSelection(ComboMultiSelection.Off).TextKey("UserName").Height("22").Width("130").Render()

</div>

</td>

</tr>
}

SCRIPT

<script type="text/javascript">
$(document).delegate("#ddlEmployee", "igcomboselectionchanged",
function (evt, ui) {
alert('1');
// Clear the selected item table and hide the div
if (ui.items && ui.items[0]) {
//alert('2');
var myRecipe = new ProgrammeAllotmentModel();
myRecipe.FinancialYearIDKey = ui.items[0].value;
//alert(ui.items[0].value);
//alert(myRecipe.FinancialYear);
var postData = JSON.stringify(myRecipe);
// alert('3');

$.ajax({
url: '@Url.Action("/LoadSanctionOrderForFinYr")',
type: 'POST',
data: JSON.stringify(myRecipe),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (data) {

$("#ddlSanctionOrder").igCombo({
dataSource: data.SanctionOrdersForFinYr,
valueKey: "SanctionOrderIDKey",
textKey: "SanctionOrderNo"
});
//$("#ddlSanctionOrder").val("Test San");
},

error: function () {
alert('error occured');
}

});
//alert('END');
}
});
</script>

//Please help me how to call a javascript function on selection change of any one of thid ddlEmployee

  • 29417
    Verified Answer
    Offline posted

    Hello Kishore, 

    Thank you for posting in our forum. 

    The ID of your  combos will be ddlEmployee0, ddlEmployee1 etc. So none of the IDs will actually match the selector you have set:

    $(document).delegate("#ddlEmployee",…)

    Since none of their IDs will be equal to “ddlEmployee”. 

    Instead you can add an additional attribute to the combo and set the selector so that it gets the items with that attribute.

    For example you can define a class for all of the combo: 

    @{

        Dictionary<string, object> attr = new Dictionary<string, object>();

        attr.Add("class", "igEditorClass");   

    }

    And set it as an html attribute for the combo:

    .HtmlAttributes(attr)

    And then find the combos by that class name: 

    $(function(){

    $(document).delegate(".igEditorClass", "igcomboselectionchanged",

     function (evt, ui) {

    });

    });

     

    Let me know if you have any questions.

     

    Best Regards,

    Maya Kirova

    Developer Support Engineer II

    Infragistics, Inc.

    http://www.infragistics.com/support