I am using ASP.NET MVC ( Razor ) and Jquery my page looks like below ( simplyfied ). When i first load my page everything works fine every script is working i can open datepicker etc. But after i choose from dropdown my scripts stop working. Returned result is ok( there is no problems on server side ), what it is going here is basically i send whole form to server side fills some data from database and send back content for div. Can i somehow reinitialize scripts or something, cause for me it looks like js/jquery "didnt notice" new content?
<div id="commissionContent">
<table>
<tr>
@Html.DropDownListFor(m => m.OfferId, new SelectList(Model.Offers, "Id", "DocumentNo"),
"-- Wybierz --", new { id = "selectedOffer" })
</tr>
<tr>
<td colspan="5">
@Html.LabelFor(m => m.RealizationDate)<br />
@Html.TextBoxFor(m => m.RealizationDate, new { id = "CommissionRealizationDate" })
</td>
<td></td>
<td></td>
</tr>
</div>
@section JavaScript
{
<script type="text/javascript">
$(function () {
$('#CommissionRealizationDate').datepicker({
format: "dd/MM/yyyy",
autoclose: true
});
offerType.init();
});
var offerType = {
init: function () {
//this.selectedKind();
this.selectedOffer();
},
selectedOffer: function () {
$('form').on('change', '#selectedOffer', function () {
**$.post("ChoosenCommission", $('form').serialize(), function (data) {
$("#commissionContent").html(data);**
});
}
};
}
I just noticed the same thing ed-X said, it didnt work before. Propably the problem was that i was returning from server whole page ( not just div content ) and it maybe screwd something ( anyone knows? ).
P.S. U guys are fast i just went to make a tea and was going to answer myself :P