471,119 Members | 1,226 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to detect invisibility on element contained inside invisible parent?

Hi,

I'm trying to detect if an input field is visible or not in order to
put the focus inside it (or else it cause th error : "Can't move the
focus ot the control because it is invisible, not enabled, or of a
type that does not accept the focus").

I'm using css to set the visibility. But the visibility style of the
input field itself is not set, the parent that contains the input is
the one set invisible. Here's a simple example that shows what I'm
talking about:

<table style="visibility:hidden">
<tr>
<td><input type="text" name="MyInput"/></td>
</tr>
</table>

So in this example, if you try to put the focus inside the input it
cause the error because the parent table renders it invisible.
(Myinput.style.visibility doesn't work either)

I know i could do a loop to look if any parents have the visibility
set to "hidden", but I'm searching for something more "easy",
something like the function "isDisabled" or "isContentEditable"...
(something like "isVisible" would be perfect... if it existed! )

Thanks for your time! :)

jeje
Jul 20 '05 #1
1 11188
Ivo
"Jeje" <je****@hotmail.com> wrote in message
news:f3**************************@posting.google.c om...
Hi,

I'm trying to detect if an input field is visible or not in order to
put the focus inside it (or else it cause th error : "Can't move the
focus ot the control because it is invisible, not enabled, or of a
type that does not accept the focus").


try{
document.myform.myinput.focus();
}
catch(e){
alert('Could not focus on myinput.');
}

Better than checking visibility, you want to check focusability. The
try-catch should stop any errors.
Ivo
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Markus Ernst | last post: by
4 posts views Thread by Hollywood | 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.