Code:
success : function(responseJson) { var tbody = $("#Account"); alert("JSonResponse: " + responseJson); $ .each( responseJson, function(index, account) { // Iterate over the JSON array. var value = ATYpeMap[account.AccountTypeID]; $('<tr>') .appendTo(tbody) // Create HTML <tr> element, set its text content with currently iterated item and append it to the <table>. .append( $('<td>') .text( account.AccountNumber)) // Create HTML <td> element, set its text content with id of currently iterated account and append it to the <tr>. .append( $('<td>').text( value)) // Create HTML <td> element, set its text content with name of currently iterated account and append it to the <tr>. .append( $('<td>') .text( account.AccountStatus)) .append($('<td style=\"display:none;\">').text(account.AccountTypeID)) .append( $('<select id="Accountchange"+r+ onchange="dropDownOnChange(this)"><option value=""></option><option value="Valid">Valid</option><option value="Invalid">Invalid</option></select>')) /* .append($('<button id="{account.AccountNumber}" value="ChangeAccountStatus" onclick="AccountChange(this)">ChangeAccountStatus</button>')) */; }); } }); }; var item = []; function dropDownOnChange(e) { var selectedValue=e.options[e.selectedIndex].value; alert("selectedValue:" + selectedValue); var currentRow= $(e).closest("tr"); var AccountNo= $("td:eq(0)",$(currentRow)).text(); alert("accountno"+AccountNo); var AccountType =$("td:eq(1)",$(currentRow)).text(); alert("acctyp"+AccountType); var AcctypID= $("td:eq(3)",$(currentRow)).text(); alert("accID"+AcctypID); var objddlvalue= {}; objddlvalue["AccountNo"] =AccountNo; objddlvalue["AccountType"]=AccountType; objddlvalue["Account Type_Val"]=AcctypID; objddlvalue["AccountStatus"]=selectedValue; item.push(objddlvalue); console.log(item); var jsonObj1 = JSON.stringify(item); //jsonObj1.parseJSON(); //JSONobj= JSON.parse(jsonObj1); console.log(jsonObj1); }
Comment