|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Does an element have the focus??
Hi everyone
I'm a newbye in javascript My problem is I want to know if an element of a form has the focus with a simple if statement something like that: if (document.formName.elementName.focus()==true) what is wrong in my syntax? Is this the correct method? can anyone help me? thanks in advance marco |
|
#2
|
||||
|
||||
|
What's wrong with your code is that by calling the focus() method, you're setting the focus... I presume that line would *always* return true...
I'm not sure if this is the best solution, but you could always set a global variable onBlur... example: <input type="text" name="firstName" onBlur="changeState(this, false)" onFocus="changeState(this, true)"/> Perhaps the method would look like: Code:
var nameFocus=false;
function changeState(obj, b) {
if(obj.name=="firstName") {
nameFocus=b;
}
}
This code is entirely untested and presumed not to work... perhaps it will give you a hint as to the direction to guide you to find an answer. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Does an element have the focus?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|