Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(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) {
- $("#" + id).attr('classname', 'selected');
- $("#" + id).attr('id', 'sel' + rowIndex);
- $("#" + id).attr('name', 'sel' + rowIndex); // this never works
- 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);
- $.each(data, function (GetSubCatergories, Category) {
- $('#parent_id').append($("<option></option>").
- attr("value", Category.category_id).
- text(Category.name));
- });
- }
- });
- }
- });
- });
- $("#" + id).attr('id', 'sel' + rowIndex);
- $("#" + id).attr('name', 'sel' + rowIndex); // this can't ever work
- $("#" + id).attr('id', 'sel' + rowIndex)
- .attr('name', 'sel' + rowIndex);
- $("#" + id).attr('name', 'sel' + rowIndex);
- $("#" + id).attr('id', 'sel' + rowIndex);
- var $el = $("#" + id);
- $el.attr("id", 'sel' + rowIndex);
- ...
- $("#" + id).attr('classname', 'selected');
- $("#" + id).attr('id', 'sel' + rowIndex);
- $("#" + id).attr('name', 'sel' + rowIndex);
- $("#" + id).attr('name', 'sel' + rowIndex);
- $("#" + id).attr('classname', 'selected');
- $("#" + id).attr('id', 'sel' + rowIndex);
- {
- "id" : "sel" + rowIndex ,
- "name" : "sel" + rowIndex
- }
Add Comment
Please, Sign In to add comment