0

I have an onclick code on my image to disable the button on my form that look like this

<img alt="" src="images/search-icon.png" width="16" height="16" style="display: inline;height:16px;cursor:pointer; width: 16px;" onclick="DisableButton('<%=btnSave.ClientID %>');" />

And then on my javascript I have a code like this

function DisableButton(bSave) {
document.getElementById(bSave).attributes("Enabled", false);
}

the problem is it is not working, everytime i click on the image nothing happens. Is there an error on my code? Please help me on this one. Thank you in advance.

3
  • 2
    There is no attributes in JavaScript and there is no Enabled property in HTML. Commented Jan 9, 2015 at 5:38
  • Use document.getElementById("idofyourbutton").disabled=true; Commented Jan 9, 2015 at 5:39
  • That's not keyboard accessible. To fix it, wrap the img in a button, move the onclick to the button and change the alt text to alt="search". Commented Jan 9, 2015 at 5:39

3 Answers 3

1

Use 'disabled'

document.getElementById(bSave).disabled = true;

http://www.w3schools.com/jsref/prop_html_disabled.asp

Clearing up the disable vs disabled ambiguity.

Sign up to request clarification or add additional context in comments.

1 Comment

Adding with example could be better
0

Here's code :

 document.getElementById(bSave).disabled = true;

Or

document.getElementById('<%= btnSave.ClientID %>').disabled = true;

3 Comments

I've tried your code but it is still not working. is ".disable" right?
There's no error, nothing happens when i click the image.
Do you know how to brower debugger like developer tools
0

Please use this it will work In your script :

document.getElementById(bSave).disabled = true;

if you are using jquery then

 $("#"bSave).prop("disabled",true);

1 Comment

Then ? Check your answer your code will not work because it is not disable it is disabled

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.