Problem removing readOnly in IE

J

J. McConnell

I am having trouble with the following code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>
</head>
<body>
<input value='test' type='text' readonly='readonly'
onfocus='this.readOnly = false;'
onblur='this.readOnly = true;'></input>
</body>
</html>

In FF, this works as I would expect. When clicking on the input, the readOnly
property is set to false and the focus is given to the element, with the
cursor placed after the last character.

In IE, the readOnly property is set to false, but the element isn't actually
given focus. Instead, I have to click on the input a second time in order to
actually input text with the keyboard.

Is there a way to make this work the same in IE as it does in FF? I have
tried things like calling this.focus() and this.click() after setting
readOnly to false, but they have no effect.

Any help would be greatly appreciated.

Thank you,

- J.
 
E

Erwin Moller

J. McConnell said:
I am having trouble with the following code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>
</head>
<body>
<input value='test' type='text' readonly='readonly'

Hi,

Maybe you confused IE because you set the value to 'readonly' instead of the
expected boolean true or false.

And maybe onMouseOver with onMouseOut works better. Giving focus to a
readonly-element possibly made little sense to the IE developers.

Give that a shot.

Regards,
Erwin Moller
 
J

J. McConnell

I am having trouble with the following code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>
</head>
<body>
<input value='test' type='text' readonly='readonly'

Maybe you confused IE because you set the value to 'readonly' instead of the
expected boolean true or false.[/QUOTE]

I gave this a shot, setting the value to true or false, and it didn't
make a difference. Anyway, "readonly" is the only valid value in XHTML.
And maybe onMouseOver with onMouseOut works better. Giving focus to a
readonly-element possibly made little sense to the IE developers.

Actually, onMouseOver and onMouseOut did work. Unfortunately, it
doesn't do me any good because you can't tab into the control. Also, I
recently read that one difference between readonly and disabled is that
readonly elements can receive focus while disabled elements can't.

I do agree that this is an edge case and arguably not the best way to go
about this, but do to circumstances beyond my control it would be
difficult to go another route, like never setting the element to
readonly in the first place.

Thanks for the suggestions,

- J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top