Connecting Tech Pros Worldwide Help | Site Map

How to detect invisibility on element contained inside invisible parent?

  #1  
Old July 20th, 2005, 11:56 AM
Jeje
Guest
 
Posts: n/a
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
  #2  
Old July 20th, 2005, 11:56 AM
Ivo
Guest
 
Posts: n/a

re: How to detect invisibility on element contained inside invisible parent?


"Jeje" <jerars@hotmail.com> wrote in message
news:f3a207c2.0310031141.44bd52f7@posting.google.c om...[color=blue]
> 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").[/color]

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


Closed Thread