Not sure why this isn't working.
When people click the 'edit' button of my application, the disabled textfields become editable:
$("#bewerken").click(function(e) {
$("input[disabled='disabled']").removeAttr('disabled');
});
I then want to disable the textfields again when the user saves; I have this code bound to my save button:
$("#save_school_changes").click(function(e) {
//stuff
$.ajax({
type: "POST",
url: "/school/save_changes",
data: { //stuff },
success: function(data)
{
$("#feedback_top").html("<p>" + data['message'] + "</p>").slideDown('slow').delay(2000).slideUp();
$("input[type='text']").attr('disabled', 'disabled');
}
});
e.preventDefault();
});
As far as I know, this should disable the textfields again. However, this does not seem to be working in Chrome. It does work in Firefox. I haven't had the chance to test in IE or Safari yet. Is there any way to make this work in Chrome aswell? Thanks a lot!
Here:
http://jsbin.com/urize4/edit
Live Preview
http://jsbin.com/urize4/
You should use "
readonly
" instead like:Try
$("input[type='text']").attr('disabled', true);
If you are using jQuery < 1.6 do this:
If you are using jQuery 1.6+:
See this question: .prop() vs .attr() for references why.
Or you can try this:
see here for info on
:text
For me, none of these answers worked, but I finally found one that did.
I needed this for IE-
I also had to add this for Chrome and Firefox -
and this -
Have you tried with prop() ??
Well prop() seems works for me.
if you are removing all disabled attributes from input, then why not just do:
Then after ajax success:
Make sure you use remove the disabled attribute before submit, or it won't submit that data. If you need to submit it before changing, you need to use readonly instead.