Reputation: 40564
I've been using the disabled
attribute on input text boxes to make them uneditable. The problem is I can't change the font color of a disabled
field in IE.
So I'm trying to change all the disabled
fields to readonly
fields on page load using the following code:
$("input[type=text][disabled]").attr("readonly","readonly").removeAttr("disabled");
No matter where I put the above code it does not work. But when I run it in the script console it works.
UPDATE:
Found the reason. I am using ASP.NET Ajax which provides a pageLoad
-- in my case the code inside pageLoad
was disabling my textboxes. Added the above code at the end of 'pageLoad' event and it works perfectly. Thanks!
Upvotes: 1
Views: 731
Reputation: 6544
You can try that inside the onload event,
$( document ).ready(function() {
$("input[type=text]:disabled").attr("readonly","readonly").removeAttr("disabled");
});
Upvotes: 1
Reputation: 1208
Try
$(function() { /* your code */ });
this will execute the code after the page has been loaded.
Upvotes: 4