jQuery Suspected Naming Convention Problem -


i'm having problem jquery function, portion of function renames id, class , name of dropdown works first dropdown, subsequent ones not work, ideas?

i suspect may have naming convention in cat.parent_id required asp.net mvc model binding.

$(document).ready(function () {      $("table select").live("change", function () {          var id = $(this).attr('id');          if ($(this).attr('classname') != "selected") {              var rowindex = $(this).closest('tr').prevall().length;             $.getjson("/category/getsubcategories/" + $(this).val(), function (data) {                 if (data.length > 0) {                      //problematic portion                     $("#" + id).attr('classname', 'selected');                     $("#" + id).attr('name', 'sel' + rowindex);                     $("#" + id).attr('id', 'sel' + rowindex);                      var position = ($('table').get(0));                      var tr = position.insertrow(rowindex + 1);                     var td1 = tr.insertcell(-1);                     var td2 = tr.insertcell(-1);                     td1.appendchild(document.createtextnode('subcategory'));                     var sel = document.createelement("select");                     sel.name = 'parent_id';                      sel.id = 'parent_id';                      sel.setattribute('class', 'unselected');                     td2.appendchild(sel);                     $('#parent_id').append($("<option></option>").attr("value", "-1").text("-please select item-"));                      $.each(data, function (getsubcatergories, category) {                         $('#parent_id').append($("<option></option>").                                 attr("value", category.category_id).                                 text(category.name));                      });                     sel.name = 'cat.parent_id';                     sel.id = 'cat.parent_id';                 }              });          }     }); });  

you're trying set id of selected id can't start.

$("#" + id).attr('id', 'sel' + rowindex); // shouldn't think 

i think want replace line

var id = $(this).attr('id'); 

with

var currentdropdown = this; 

then when want access inside getjson this:

$(currentdropdown) 

so problematic portion like:

$(currentdropdown).attr('classname', 'selected'); $(currentdropdown).attr('name', 'sel' + rowindex); $(currentdropdown).attr('id', 'sel' + rowindex); 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -