Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
how to use splice when remove index of course
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
ahmed salah
8y
409
1
Reply
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>
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Need code for black circle bullet point
file upload through ajax request