javascript - jQuery Status change True false Image Button -


this jquery code bind html table.i have 2 image...how can check when true 1.jpg show , when false 2.jpg show.

$(function () {     debugger     $.ajax({         type: "post",         contenttype: "application/json; charset=utf-8",         url: "webform5.aspx/binddatatable",         data: "{}",         datatype: "json",         success: function (dt) {             debugger;             (var = 0; < dt.d.length; i++) {                 $("#example1 > tbody").append("<tr><td> <input type='checkbox' class='chk' id=" + dt.d[i].categoryid + " /></td><td>" + dt.d[i].categoryid + "</td><td>" + dt.d[i].name + "</td><td><input type='image'if() src='images/1.png'title='deactivate this'  value=" + dt.d[i].status + " alt='submit' width='18' height='18'>  </td><td> <i class='ui-tooltip fa fa-pencil' onclick='btnquerystring_click(" + dt.d[i].categoryid + ")' style='font-size:22px;margin-left: 32px;'></i><i class='ui-tooltip fa fa-trash-o' onclick='deleterecord(" + dt.d[i].categoryid + ")' style='font-size: 22px;margin-left: 32px;'></i> </tr>");             }             $("#example1").datatable();         },         error: function (result) {             alert("error");         }     }); }); 

i taking image <input type='image'> tag.

<input type='image' src='images/1.png'title='deactivate this'  value=" + dt.d[i].status + " alt='submit' width='18' height='18'>  

guide me how can check status value true or false , how show in table status column?? note:if using using + dt.d[i].status + shows output true or false in table.

first things first,

  • the last </td> missing
  • remove if() input element, that's invalid html
  • replace ' \' , " ' keep format intact

so, putting inside loop should work

var image=''; if( dt.d[i].status == true ) {   image = '1.jpg'; }else{   image = '2.jpg'; }  var data = '<tr>  <td> <input type=\'checkbox\' class=\'chk\' id=' + dt.d[i].categoryid + ' /></td><td>' + dt.d[i].categoryid + '</td>  <td>' + dt.d[i].name + '</td>  <td><input type=\'image\' '+ image +' src=\'images/unblock.png\' title=\'deactivate this\' value=' + dt.d[i].status + ' alt=\'submit\' width=\'18\' height=\'18\'> </td>  <td>     <i class=\'ui-tooltip fa fa-pencil\' onclick=\'btnquerystring_click(' + dt.d[i].categoryid + ')\' style=\'font-size:22px;margin-left: 32px;\'></i>    <i class=\'ui-tooltip fa fa-trash-o\' onclick=\'deleterecord(' + dt.d[i].categoryid + ')\' style=\'font-size: 22px;margin-left: 32px;\'></i>    </td></tr>';  $("#example1 > tbody").append(data); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -