jquery: textbox contracts onblur and button beside it moves with it... and can't be clicked?

AidenA
AidenA used Ask the Experts™
on
Hi, as the title suggests, I wondering what's the best way to deal with this situation. I have a textbox and button beside it (on the right side) in a flow layout. I use jquery to expand the textbox to the right which then pushes the button to the right also.

The problem is I want to contract the textbox back to it's original size when it loses focus (onblur even). But, if you have the situation where it loses focus because the user wants to click that button then it doesn't seem to work as the button moves to the left with the contracting textbox, but the click even doesn't appear to have been fired.

How exactly would I get around this situation so that the click even of the button fires before it moves to the left due to the contracting textbox because it's onblur even was fired?

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
A.) Call the click event from the onblur event
B.) Put the blur functionality in the buttons click event

Author

Commented:
ok thank for that, just not sure how to implement that yet...

first i need to check if the button hasfocus which i can't quite see how to do? then i need to call the buttons click event... could you provide code example?
if(btnName.Focused)
{
         btnName_Click(null, null);
}

Open in new window

Commented:
ok thanks,

went for a slightly messy global variable approach where i set it under certain conditions as below. The textbox will only resize if blnShowTasks  = false. So, if the mouse goes over the button then blnShowTasks = true, if it goes out then blnShowTasks = false. Then the button can be clicked without anything changing (as blnShowTasks = true if mouse is over button) and i can reset the textboxes width after that in button click event. If the button isn't clicked then the textbox will resize as previously since blnShowTasks = false


 function txtTypeDescExpand()
    {
        $("#txtTypeDesc").animate({width:'50em'}, 200)
     }
function btnShowTasksMouseOver(){
        window.blnShowTasks = true;
    }
function btnShowTasksMouseOut(){
        window.blnShowTasks = false;
    }
function btnShowTasksOnClick(){
                $("#txtTypeDesc").animate({width:'18.2em'}, 200)
            }
 function txtTypeDescContract()
            {
                if (!(window.blnShowTasks == true)){
                    $("#txtTypeDesc").animate({width:'18.2em'}, 200)
                }
            }

Author

Commented:
solution found

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial