Click here to Skip to main content
14,700,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Problem

when remove any course from table list html his position in center or first it make problem

in index in database

Details

IF I have list of courses as following :

Delphi

Flash

Photoshop

IF I remove flash by JQUERY remove button then click save button

it delete flash and Photoshop

because there are wrong in delete courses by using remove function in jquery

if i remove php it is working without any problem because it is last item

suggestion

using map function when remove but how to do that

if there are any solution for that without using map no problem

i use model as following

public class Cusomemp2
    {
        public List<EmployeeCourse> empcourses { get; set; }
 
    }
}

in model view my code as following by jquery

actually i need to modify code below using map function if there are any function do that never mind

<pre>$(function () {
           //add courses using drop down
            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 () {
              // remove function
                $(this).parent().parent().remove();
 
                $(this).parent().prev().prev().remove();
             });
 
// retrieve data in edit view using ajax
            $.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++;
                    });
                }
 
            })
        });




Simple File Sharing and Storage.[^]

What I have tried:

when remove course by using jquery index have problem
Posted
Updated 18-Sep-16 7:36am
Comments
Patrice T 18-Sep-16 12:45pm
   
This question look furiously like your previous one.
ahmed_sa 18-Sep-16 13:01pm
   
thank you for reply
but in previous thread i not get answer so that i ask again
if i have error i will make debug but i know my problem found in index
and i need to use function map to index or any function solve the problem

1 solution

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.

Quote:
can you help me tou use map function

Your code don't the map function.
JavaScript Array map() Method[^]
[Update]
There is no shortcut to knowledge, no one can learn for you, you are the only one that can do it.
   
v3
Comments
ahmed_sa 18-Sep-16 12:45pm
   
can you help me tou use map function
i will use debugger to know what is the problem
but here i know problem and i need to solve
my question how to map index when using remove by jquery
ahmed_sa 18-Sep-16 13:06pm
   
can you help me how to use in code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900