Guest User

Untitled

a guest
Mar 21st, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. $(document).ready(function () {
  2.  
  3. $("table select").live("change", function () {
  4.  
  5. var id = $(this).attr('id');
  6.  
  7. if ($(this).attr('classname') != "selected") {
  8. var rowIndex = $(this).closest('tr').prevAll().length;
  9. $.getJSON("/Category/GetSubCategories/" + $(this).val(), function (data) {
  10. if (data.length > 0) {
  11.  
  12. $("#" + id).attr('classname', 'selected');
  13. $("#" + id).attr('id', 'sel' + rowIndex);
  14. $("#" + id).attr('name', 'sel' + rowIndex); // this never works
  15.  
  16. var position = ($('table').get(0));
  17.  
  18. var tr = position.insertRow(rowIndex + 1);
  19. var td1 = tr.insertCell(-1);
  20. var td2 = tr.insertCell(-1);
  21. td1.appendChild(document.createTextNode('SubCategory'));
  22. var sel = document.createElement("select");
  23. sel.name = 'parent_id';
  24.  
  25. sel.id = 'parent_id';
  26.  
  27. sel.setAttribute('class', 'unselected');
  28. td2.appendChild(sel);
  29.  
  30. $.each(data, function (GetSubCatergories, Category) {
  31. $('#parent_id').append($("<option></option>").
  32. attr("value", Category.category_id).
  33. text(Category.name));
  34. });
  35. }
  36.  
  37. });
  38.  
  39. }
  40. });
  41. });
  42.  
  43. $("#" + id).attr('id', 'sel' + rowIndex);
  44. $("#" + id).attr('name', 'sel' + rowIndex); // this can't ever work
  45.  
  46. $("#" + id).attr('id', 'sel' + rowIndex)
  47. .attr('name', 'sel' + rowIndex);
  48.  
  49. $("#" + id).attr('name', 'sel' + rowIndex);
  50. $("#" + id).attr('id', 'sel' + rowIndex);
  51.  
  52. var $el = $("#" + id);
  53. $el.attr("id", 'sel' + rowIndex);
  54. ...
  55.  
  56. $("#" + id).attr('classname', 'selected');
  57. $("#" + id).attr('id', 'sel' + rowIndex);
  58. $("#" + id).attr('name', 'sel' + rowIndex);
  59.  
  60. $("#" + id).attr('name', 'sel' + rowIndex);
  61. $("#" + id).attr('classname', 'selected');
  62. $("#" + id).attr('id', 'sel' + rowIndex);
  63.  
  64. {
  65. "id" : "sel" + rowIndex ,
  66. "name" : "sel" + rowIndex
  67. }
Add Comment
Please, Sign In to add comment