Test if text box is readonly

H

harry

<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
 
Z

ZER0

<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.)
 
H

harry

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 said:
<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.)
 
Z

ZER0

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"
 
H

harry

Excellent! works perfectly - thanks again!

ZER0 said:
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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top