Problem removing readOnly in IE

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,
LVL 3
Abdu_AllahAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ronan1979Commented:
note:
the simple fact you have the attribute readonly even with no value will make it read only

readonly has only one value possible : 'readonly' see http://www.w3.org/TR/html401/interact/forms.html
= read only =
<input value='test' type='text' readonly=''></input>
=read and write =
<input value='test' type='text' ></input>
0
ronan1979Commented:
you need to set/delet the attribute readonly

 document.myForm.myInput.setAttribute('readonly','readonly');
 document.myForm.myInput.removeAttribute('readonly');

<?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>
<form name="myForm">
<input name="myInput" value='setA' type='text'></input>
<input value='test' type='text' readonly=''></input>
<input value='test' type='text' ></input>


<script>
fnReadOnly = function () {
  document.myForm.myInput.setAttribute('readonly','readonly');
}
fnReadWrite = function () {
  document.myForm.myInput.removeAttribute('readonly');
}

init = function () {
document.myForm.myInput.onfocus = fnReadWrite;
document.myForm.myInput.onblur = fnReadOnly;
if(document.myForm.myInput.focused) {
  fnReadOnly();
  }

}

window.onload = init;

</script>

</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Abdu_AllahAuthor Commented:
It does not work!
0
ronan1979Commented:
for IE

document.myForm.myInput.readOnly = true; // or false

0
ronan1979Commented:
i dont understand what you are trying to do.

even if redOnly is set, you can modify the value with a javascript code:

 document.myForm.myInput.value="hello";

readOnly is only concern for keyboard/mouse modification.

in your case, readOnly seems have no meaning
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.