javascript - When click table row alert that value -
i want, when click table row below function process.. got output when double click show result.. need single click result
here javascript:
function found(row) { if (document.getelementbyid('ridee').checked) { var table=document.getelementbyid("table"); var rows = table.getelementsbytagname("tr"); for (var = 0; < rows.length; i++) { rows[i].onclick = (function() { // closure return function() { $('#loading').show(); var result = this.cells[1].textcontent; var plate = this.cells[6].textcontent; var km = this.cells[7].textcontent; var datastring = 'plate=' + plate + '&km='+km + '&res='+result; $.ajax({ type: 'post', url: 'km.php', async: true, data: datastring, cache: false, global: false, success: function(result) { $('#loading').hide(); var answer = confirm(result); if (answer == true) { return test(); } } }); } })(i); } } else { alert("you rider... so, can't select"); } }
i thought return function problem.. without return function not working.. please help
thanks in advance..
this lot easier if each functional component split out.
function gettablerows() { var table = document.getelementbyid("table"); return table.getelementsbytagname("tr"); } function builddatastringfromrow(row) { var result = row.cells[1].textcontent; var plate = row.cells[6].textcontent; var km = row.cells[7].textcontent; return 'plate=' + plate + '&km='+km + '&res='+result; } function postdata(datastring, callback) { $.ajax({ type: 'post', url: 'km.php', async: true, data: datastring, cache: false, global: false, success: callback }); } function onrowclick() { $('#loading').show(); var datastring = builddatastringfromrow(this); postdata(datastring, function(result) { $('#loading').hide(); var answer = confirm(result); if (answer == true) { return test(); } } } function found(row) { var tablerows = gettablerows(); if (document.getelementbyid('ridee').checked) { (var = 0; < tablerows.length; i++) { tablerows[i].onclick = onrowclick.bind(tablerows[i]); } } else { alert("you rider... so, can't select"); } }
now each function simple , easy remove, may reason part not working.
Comments
Post a Comment