473,516 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Test if text box is readonly

<input type="text" name="actreqto" maxlength="20" value=""
onkeypress="changedDetails();" onchange="changedDetails();"
readonly="readonly">

Any ideas why doesn't this work?

alert(top.document.forms[0].actreqto.readonly);

displays 'undefined'

alert(top.document.forms[0].actreqto.readonly=='readonly');

displays 'false'

thanks

harry
Jul 23 '05 #1
4 11299
On Sun, 16 May 2004 08:57:06 GMT, harry wrote:
<input type="text" name="actreqto" maxlength="20" value=""
onkeypress="changedDetails();" onchange="changedDetails();"
readonly="readonly">

Any ideas why doesn't this work?

alert(top.document.forms[0].actreqto.readonly);
alert(top.document.forms[0].actreqto.readOnly);
alert(top.document.forms[0].actreqto.readonly=='readonly');


readOnly is a boolean.

--
C'ya,
ZER0 :: coder.gfxer.webDesigner();

"When you have eliminated the impossible, whatever remains,
however improbable, must be the truth." (S.H.)
Jul 23 '05 #2
Thanks for that Zero, was hoping to test if a key was pressed in a text box
that has readOnly set.

Any ideas why this returns false regardless of this setting?
function changedDetails()
{
alert(this.readOnly==true);
..
..
..
}

cheers

"ZER0" <ze********@libero.it> wrote in message
news:ms**************@ID-171124.news.individual.net...
On Sun, 16 May 2004 08:57:06 GMT, harry wrote:
<input type="text" name="actreqto" maxlength="20" value=""
onkeypress="changedDetails();" onchange="changedDetails();"
readonly="readonly">

Any ideas why doesn't this work?

alert(top.document.forms[0].actreqto.readonly);


alert(top.document.forms[0].actreqto.readOnly);
alert(top.document.forms[0].actreqto.readonly=='readonly');


readOnly is a boolean.

--
C'ya,
ZER0 :: coder.gfxer.webDesigner();

"When you have eliminated the impossible, whatever remains,
however improbable, must be the truth." (S.H.)

Jul 23 '05 #3
On Mon, 17 May 2004 10:33:49 GMT, harry wrote:
Thanks for that Zero, was hoping to test if a key was pressed in a text box
that has readOnly set.

Any ideas why this returns false regardless of this setting?


Yes. Because the "this" keyword in that context is NOT your HTML input
object.

Try this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title></title>
</head>

<body>
<script type="text/javascript">
function changedDetails(sender){
if (sender.readOnly)
alert("the element "+sender.name+" is readonly");
else
alert("the element "+sender.name+" is editable");
}
</script>

<input type="text" name="actreqto" maxlength="20" value=""
onkeypress="changedDetails(this);" readonly="readonly" />

</body>
</html>
--
C'ya,
ZER0 :: coder.gfxer.webDesigner();

"Nei film americani, qualsiasi problema che venga considerato
sufficientemente catastrofico, puo' essere risolto facendo esplodere uno
o piu' ordigni nucleari" (ZER0 & Cosimo)

Now playing: "No more chances"
Jul 23 '05 #4
Excellent! works perfectly - thanks again!

"ZER0" <ze********@libero.it> wrote in message
news:hc**************@ID-171124.news.individual.net...
On Mon, 17 May 2004 10:33:49 GMT, harry wrote:
Thanks for that Zero, was hoping to test if a key was pressed in a text box that has readOnly set.

Any ideas why this returns false regardless of this setting?


Yes. Because the "this" keyword in that context is NOT your HTML input
object.

Try this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title></title>
</head>

<body>
<script type="text/javascript">
function changedDetails(sender){
if (sender.readOnly)
alert("the element "+sender.name+" is readonly");
else
alert("the element "+sender.name+" is editable");
}
</script>

<input type="text" name="actreqto" maxlength="20" value=""
onkeypress="changedDetails(this);" readonly="readonly" />

</body>
</html>
--
C'ya,
ZER0 :: coder.gfxer.webDesigner();

"Nei film americani, qualsiasi problema che venga considerato
sufficientemente catastrofico, puo' essere risolto facendo esplodere uno
o piu' ordigni nucleari" (ZER0 & Cosimo)

Now playing: "No more chances"

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2835
by: Art | last post by:
Hi, I'm using a form text input to display a JavaScript clock. It has no other purpose than that, just show the date and time. What I would like to do now is prevent anything else happening when it's moused over. I was able to remove the cursor using the blur() method, something like this: document.formname.inputname.blur();
3
2187
by: Roy Adams | last post by:
Hi I'm reposting this question because for some reason can't post follow up question to this thread. What I'm trying to do is put the value and text from a a select in to a text field and to a hidden field respectfully and the value from dynamically created hidden fiields in to a text fieldin to a text field all at the same time Here's...
5
5617
by: Randell D. | last post by:
Folks, I have a few <INPUT TYPE=TEXT> tags that are readonly if a specific field has no value... these work fine. However, I also have checkboxes which I would like to have as readonly, but the same code doesn't work - Can someone suggest a solution? This is sample code extracted from my original code: // Before other input tags...
35
2529
by: Cor | last post by:
Hallo, I have promised Jay B yesterday to do some tests. The subject was a string evaluation that Jon had send in. Jay B was in doubt what was better because there was a discussion in the C# newsgroup on 25 September. The regular expressions where in that newsgroup too involved. I told yesterday night, to Jay that I would test all 4...
0
2404
by: landesjoe | last post by:
Hi, here's my problem in short: Text boxes in gridview don't seem to hold their value if the column's .Visible property is changed back and forth. I've got a form with a gridview populated from a data view (which in turn is loaded from a manually setup DataTable for testing purposes). One of the columns in the grid is a checkbox that's...
3
2576
by: jonniethecodeprince | last post by:
Hi all, I have trouble getting an array of data stored in a separate javascript file i.e. a file called books.js into a table of data for a .xhtml file. There are 50 Records in this file. There are 5 colums of data I wish to display. I want to display these records in groups of 10. Based on the fact that the records I want are...
2
1858
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005, .net 2 for a windows application. I have a richtextbox control on my form that I make it readonly. 1. Do I need to make readonly to be false to append text to it? 2. Even though I chose the Cursor property of the richtextbox to be "No" but when I run the application I can still click on the RTB and got a Ibeam cursor...
7
3106
by: kirkgilbert | last post by:
I am trying to do an onchange event in a form using a text field. The form is tied to a record set that is part of a repeated region. One the first record when I edit the data it works perfectly. When I go to the second record nothing happens. I have attached the code below: I bolded text that contains the javascript and fields this is...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7548
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5714
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.