c# - Ajax call is not working on check box change function -


i trying ajax call on check box check.

here code:

 <%@ control language="c#"  inherits="system.web.mvc.viewusercontrol<emsadmin.models.user>" %>  <%@ import namespace="emsadmin.models" %> <script type="text/javascript"> //<![cdata[ alert("i here"); var manuid = ('#value'); alert(manuid);  $('#value:checkbox').change(function () {     var taskinput;     alert("i here" +'#<%: model.manufacturerid %>');     $.ajax({         url: "/reportuserverification/getcountriesformanufacturer/<%:model.manufacturerid%>",          type:'get',         success: function (data) {             taskinput = data;             var countriesarray = [];             (var = 0; < data.length; i++) {                 var item1 = data[i];                 alert(item1);                 if (item1 != null) {                     countriesarray.push(item1);                 }             }         }     }); });  //]]> 

<script type="text/javascript"> //<![cdata[ alert("i here"); var manuid = ('#value'); alert(manuid);    $('#value').change(function () {     var taskinput;     alert("i here" +'#<%: model.manufacturerid %>');     $.ajax({         url:     "/reportuserverification/getcountriesformanufacturer/<%:model.manufacturerid%>",          type:'get',         success: function (data) {             taskinput = data;             var countriesarray = [];             (var = 0; < data.length; i++) {                 var item1 = data[i];                 alert(item1);                 if (item1 != null) {                     countriesarray.push(item1);                 }             }         }     }); });  //]]> </script>  <%= html.validationsummary("edit unsuccessful. please correct errors , try   again.") %> <% using (html.beginform())  {%>  <%= html.antiforgerytoken() %> <p> <%= html.labelfor(e=>e.id,"id:") %> <%: model.id %> </p> <p> <%= html.labelfor(e=>e.personid,"person:") %> <%= html.dropdownlistfor(e => e.personid, (selectlist)viewdata["allpersons"], "select   person", new { @style = "width: 255px;" })%> <%= html.validationmessagefor(e=>e.person,"") %> </p>  <p> <%= html.labelfor(e=>e.email,"email:") %> <%= html.textboxfor(e => e.email, new { @style = "width:250px;" })%> <%= html.validationmessagefor(e=>e.email,"") %> </p> <p> <%= html.labelfor(e=>e.corporation.description,"corporation:") %> <%= html.textboxfor(e => e.corporation.description, new { @style = "width:250px;" })%> <%= html.validationmessagefor(e=>e.corporation.description,"") %> </p> <hr /> <h2>  approve user</h2>  <p>  <%= html.labelfor(e=>e.approve,"aprrove user:") %>   <%= html.checkboxfor(e=> e.approve,model.approve) %><span>&nbsp;switch on if   want     add regitrar </span> <%= html.validationmessagefor(e=>e.approve,"") %> </p> 


multi select brands if required:

  <div id ="manufacturerid"<%:model.manufacturerdescription %>>   <p>      <%= html.labelfor(e=> e.manufacturerdescription,"brand:") %>       <br/>  </p>    <%for (int = 0; < model.manufacturers.count;i++ )   {%>   <p>                  <%:html.hiddenfor(e=>e.manufacturers[i].id) %>         <%:html.checkboxfor(x => x.manufacturers[i].isselected) %>          <%:html.labelfor(x => x.countrynames[i].isselected,      model.manufacturers[i].description)%>           </p>    <%} %>   </div>   <%--<p>   <%= html.labelfor(e=>e.manufacturerdescription,"brand:") %>   <%= html.dropdownlistfor(e => e.manufacturerdescription,    (selectlist)viewdata["allmanufacturers"], "select  brands", new { @style = "width:      255px;" })%>    <%= html.validationmessagefor(e=>e.manufacturerdescription,"") %>  </p>   <%= html.labelfor(e=>e.countryname,"country:") %> <%= html.dropdownlistfor(e => e.countryname, (selectlist)viewdata["allcountries"],  "select countries", new { @style = "width: 255px;" })%> <%= html.validationmessagefor(e=>e.countryname,"") %> </p>--%>  <hr />  <h2>  select role:</h2>  <p>  <%= html.labelfor(e => e.role, "role:")%>  <%= html.dropdownlistfor(e => e.role, (selectlist)viewdata["allroles"], "select    roles",  new { @style = "width: 255px;" })%> <%= html.validationmessagefor(e=>e.role,"") %> </p> <p> <input type="submit" value="save" /> <%= html.actionlink("cancel","details",new {id=model.id},new {@title="exit without   saving"}) %>  </p>  <% } %> 

at first, @ each iteration of for loop generating div same id. illegal in html have several elements same id on page, , javascript behavior in case unpredictable.

at second, $('#value') selects element id="value", div. div not raise change event if of content has changed. handle selection changes of checkbox, need adjust selector query checkbox itself. example, this:

$('#value :checkbox').change(function () { 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -