Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making an input field ReadOnly

Status
Not open for further replies.

alshebli

Programmer
Feb 22, 2005
10
US
Hi,

So here's my problem. I wrote a program that opens a child window. I get data from the child window and output the value in an form's input value field in the parent window, like this:

window.opener.document.myForm.elements.value = data;

This works. Now, my question is I want the input field on the parent window to be read-only as well(i.e. turns grey) after inserting the data from the child window.

Its soo simple, yet I can't seem to figure it out! :S

Thanks! any hint helps. :)
 
Code:
window.opener.document.myForm.elements[i].readOnly = true;
Be aware that this is NOT the same as disabling the field, and may not make it turn gray like you want. The field can also still recieve focus. I think you really want to DISABLE the field:
Code:
window.opener.document.myForm.elements[i].disabled = true;



Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 

The input will have several properties you can use: disabled and readOnly.

You can use these like this:

Code:
var el = widow.opener.document.forms['myForm'].elements[i];
el.value = data;
el.readOnly = true;
el.disabled = true;

You don't neccesarily have to use both disabled and readOnly - experiment and see what is right for you.

If you want, you can also change the background colour using:

Code:
el.style.backgroundColor = '#999999';

or whatever other colour suits.

Hope this helps,
Dan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top