The 'readonly' html attribute stops the text entry when I add it to the original html, but not if I add it via javascript

advertisements

Possible Duplicate:
add “readonly” to <input > (jQuery)

This is so weird, I hope there is a simple explanation. I am working with Rails, but I don't think that matters.

I add the readonly attribute to my project html element directly, I load the page and the input field behaves as readonly, like it should. After the page loads, the element looks like this:

<input class="span6" id="event_title" name="event[title]" readonly="readonly" size="30" type="text" value="test">

But I really want to add it through jquery. When I do that with:

$('#event_title').attr(readyonly", "readonly")

After the page loads, the element looks like this:

<input class="span6" id="event_title" name="event[title]" size="30" type="text" value="test" readyonly="readonly">

But the field is still editable and has no sign of being read only! Please help....


You've misspelled "readonly" in $('#event_title').attr(readyonly", "readonly") - you got "readyonly" as 1st param :-)