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
- @model WebCourse.Models.Cusomemp2
- @{
- Layout = null;
- }
-
- <!DOCTYPE html>
-
- <html>
- <head>
- <meta name="viewport" content="width=device-width" />
- <title>Edit</title>
- <script src="~/scripts/jquery-1.10.2.js"></script>
- <script>
- $(function () {
-
- var index = 0;
- $("#CourseId").change(function () {
-
- var id = $(this).val();
- var txt = $("#CourseId option:selected").text();
- $("#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>")
-
- index++;
- });
- $("#tb").on("click", ".r", function () {
- $(this).parent().parent().hide();
- $(this).parent().prev().prev().find("input").val("0");
- });
- $.ajax({
- url: "/Employee/getcoursesbyempid",
- data:{x:$("#hid").val()},
- success: function (res) {
- $.each(res, function (i, e) {
- $("#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>")
-
- index++;
- });
- }
-
- })
- });
- </script>
- </head>
- <body>
- <div>
- @using (Html.BeginForm())
- {
- <div>
- <input type="hidden" value="@ViewBag.hid" id="hid" />
- Name: @Html.TextBoxFor(a => a.Name)
- <br />
- District:<select id="districtlist" name="DistrictId"></select>
- <br />
- Courses:@Html.DropDownList("CourseId")
- <br />
- <table id="tb"></table>
- <input type="submit" value="save" />
-
- </div>
-
- }
- </div>
- </body>
- </html>