Broow Broow - 1 year ago 130
Javascript Question

How to put image inside a button in JS or how to disabled a image button when condition is meet?

I have this code in my JQgrid to create a button inside a grid

afterInsertRow: function (rowid) {
var obj = jQuery("#FiTATimeCorrectionV2List").getRowData(rowid);
var FADTLSID = obj.FitaAssignDtlID;
if (FADTLSID !== undefined) {
if (FADTLSID !== "") {
var btnApprove = "<img alt='' src='../../Content/Images/newimages/check.png' style='height:20px;width:20px;' style ='width: 90px' id='btnApprove" + rowid + "' onclick='clickmeapproved(" + rowid + " )' />"
var btnDisApprove = "<img alt='' src='../../Content/Images/newimages/delete.png' style='height:20px;width:20px;' style ='width: 90px' id='btnApprove" + rowid + "' onclick='clickmedisapproved(" + rowid + " )' />"
jQuery("#FiTATimeCorrectionV2List").setRowData(rowid, { FitaCorForApproval: btnApprove });
jQuery("#FiTATimeCorrectionV2List").setRowData(rowid, { FitaCorForDisApproval: btnDisApprove });
var temp = obj.FitaStatus;
if (temp == "Approved") {
$("#btnApprove" + rowid).attr("disabled", true);
$("#btnDisApprove" + rowid).attr("disabled", true);
} else {
$("#btnApprove" + rowid).attr("disabled", false);
$("#btnDisApprove" + rowid).attr("disabled", false);

That kind of code is in image format however the code for disable is not working if I change to
<input type = 'button'
the code is working and the image disappear. I just want to create a image button which if a condition has been meet the image button is disabled. What I want is after the data loaded the image button/s will be
if the condition is meet. As code above when the
I want to disabled all the image button/s.

Answer Source

Use jQuery's .prop method.

$("button:eq(0)").attr("disabled", false);
$("button:eq(1)").attr("disabled", true);
<script src=""></script>

<button>1. button</button>
<button>2. button</button>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download