HighTechTalks DotNet Forums  

How to set a text box to readonly using javascript?

Dotnet Scripting microsoft.public.dotnet.scripting


Discuss How to set a text box to readonly using javascript? in the Dotnet Scripting forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Alice
 
Posts: n/a

Default How to set a text box to readonly using javascript? - 08-15-2005 , 04:29 AM






i have a table look like this:

--------------
[0] |apple | (readonly)
---------------
[1] | |
---------------

i can put [0].value to [1].value by entering the following script.
<script language="javascript">
document.all[txtField_1].value = document.all[txtField_0].value
</script>

However, the problem is i want to get the [0].readonly to [1] as well, i
failed to do that.
i've tried
if (document.all[txtField_0].readonly=true)
{
document.all[txtField_1].readonly=true;
}
else
{
document.all[txtField_1].readonly=false;
}

Please help

Reply With Quote
  #2  
Old   
Ric Paton
 
Posts: n/a

Default Re: How to set a text box to readonly using javascript? - 08-29-2005 , 11:05 AM






Alice wrote:
Quote:
if (document.all[txtField_0].readonly=true)
{
document.all[txtField_1].readonly=true;
}
else
{
document.all[txtField_1].readonly=false;
}


The main problem there is your use of = instead of ==, the former an
assignment, the latter a comparison.

The second is your use of .readonly rather than .readOnly (remember JS
is case sensitive).

Although I wouldn't use the document.all collection - preferring the
standards compliant w3c method of document.getElementById() - however as
you are using it for your example, I will do the same..

document.all[txtField_1].readOnly = document.all[txtField_1].readOnly;

Hope this helps.

Ric.

A simple change of if (element.readOnly == true)_



Reply With Quote
  #3  
Old   
Shahab Khan
 
Posts: n/a

Default Re: How to set a text box to readonly using javascript? - 08-29-2005 , 07:11 PM





Use document.all[txtField_1].readOnly=true;


"readonly" is case sensitive

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.