ahmed salah

ahmed salah

  • NA
  • 530
  • 148.9k

error [object Object] get value of ids(loop to remove class

Oct 2 2016 1:45 AM

In example below i have 3 courses for employee michel

I have 3 courses per employee
c#       removebutton
sql      removebutton
java    removebutton
i need to remove sql and java and store values in ids variable
i do it but when check variable ids it give me error

i check value of ids it give me error

local host 3642 says [object Object]

  1.   <script>  
  2.         $(function () {  
  3.               
  4.             var index = 0;  
  5.              
  6.             $("#tb").on("click"".r"function () {  
  7.                
  8.                   $(this).parent().parent().hide();  
  9.                    
  10.                   $(this).parent().prev().prev().find("input").addClass("remove");  
  11.                 
  12.                     
  13.              });  
  14.             var ids = {};  
  15.             var i = 0;  
  16.             $(".remove").each(function () {  
  17.                 ids[i] = $(this).val();  
  18.                 i++;  
  19.             });  
  20.             $('#removeid').click(function () {  
  21.                 alert(ids);  
  22.             });  
  23. // to get values of courses when page loaded  
  24.             $.ajax({  
  25.                 url: "/Employeedata/getcoursesbyempid",  
  26.                 data:{x:$("#hid").val()},  
  27.                 success: function (res) {  
  28.                     $.each(res, function (i, e) {  
  29.   
  30.   
  31.   
  32.                         $("#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>")  
  33.   
  34.   
  35.   
  36.                         index++;  
  37.                     });  
  38.                 }  
  39.   
  40.             })  
  41.         });  
  42.     </script>  
  43. </head>  
  44. <body>  
  45.     <div>  
  46.         
  47.                 <input type="hidden" value="@ViewBag.hid" id="hid" />  
  48.                 
  49.                  
  50.                 <input type="submit" value="save" />  
  51.                 <input type="submit" value="getvalue" id="removeid" />  
  52.   
  53.             </div>  
  54.             <table id="tb">  
  55.   
  56.             </table>  
  57.         }  
 

Answers (10)