ahmed salah

ahmed salah

  • NA
  • 530
  • 149.8k

how to use splice when remove index of course

Sep 16 2016 12:49 PM
i need to remove  index of courses so that i need to use splice 
how to using splice to return remove courses and added courses
my code as following by jquery and i need to convert to java script by using splice if possible
  1. @model WebCourse.Models.Cusomemp2  
  2. @{  
  3.     Layout = null;  
  4. }  
  5.   
  6. <!DOCTYPE html>  
  7.   
  8. <html>  
  9. <head>  
  10.     <meta name="viewport" content="width=device-width" />  
  11.     <title>Edit</title>  
  12.     <script src="~/scripts/jquery-1.10.2.js"></script>  
  13.     <script>  
  14.         $(function () {  
  15.           
  16.             var index = 0;  
  17.             $("#CourseId").change(function () {  
  18.   
  19.                 var id = $(this).val();  
  20.                 var txt = $("#CourseId option:selected").text();  
  21.                 $("#tb").append("<tr><td><input type = 'hidden' name='empcourses[" + index + "].CourseId' value='" + id + "'/></td><td>" + txt + "</td><td><input type='button' value='remove' class='r'</td></tr>")  
  22.   
  23.                 index++;  
  24.             });  
  25.             $("#tb").on("click"".r"function () {  
  26.                 $(this).parent().parent().hide();  
  27.                 $(this).parent().prev().prev().find("input").val("0");  
  28.             });  
  29.             $.ajax({  
  30.                 url: "/Employee/getcoursesbyempid",  
  31.                 data:{x:$("#hid").val()},  
  32.                 success: function (res) {  
  33.                     $.each(res, function (i, e) {  
  34.                         $("#tb").append("<tr><td><input type = 'hidden' name='empcourses[" + index + "].CourseId' value='" + e.Id + "'/></td><td>" + e.CourseName + "</td><td><input type='button' value='remove' class='r'</td></tr>")  
  35.   
  36.                         index++;  
  37.                     });  
  38.                 }  
  39.                   
  40.             })  
  41.         });  
  42.     </script>  
  43. </head>  
  44. <body>  
  45.     <div>  
  46.         @using (Html.BeginForm())  
  47.         {  
  48.             <div>  
  49.                 <input type="hidden" value="@ViewBag.hid" id="hid" />  
  50.                 Name: @Html.TextBoxFor(a => a.Name)  
  51.                 <br />  
  52.                 District:<select id="districtlist" name="DistrictId"></select>  
  53.                 <br />  
  54.                 Courses:@Html.DropDownList("CourseId")  
  55.                 <br />  
  56.                 <table id="tb"></table>  
  57.                 <input type="submit" value="save" />  
  58.   
  59.             </div>  
  60.   
  61.         }  
  62.     </div>  
  63. </body>  
  64. </html>  
 

Answers (1)