how to use splice to remove course from jquery code
in the view model i need to remove the course from course list using splice by javascript
i need to delete index without any problem so that i use splice
how to do that 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" />
- Courses:@Html.DropDownList("CourseId")
- <br />
- <table id="tb"></table>
- <input type="submit" value="save" />
- </div>
- }
- </div>
- </body>
- </html>
the code above using for remove course from list using jquery as image
i need to replace code above for remove by using splice
because i need actually delete index by javascript