471,073 Members | 1,161 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

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 11162
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Art | last post: by
3 posts views Thread by Roy Adams | last post: by

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.