• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 62
  • Last Modified:

dont remove if focus

I'm trying to build by own function which can set the data of a textbox by showing a div which has the options and allowing the user to click on it to set it. Ive soo far done:-
http://jsfiddle.net/c57uga1c/

And it works fine to the point of showing the div however the user cannot select the 'hello' div to set it.

Im a bit stuck on how to keep the div showing but remove it if the user selects something else. Im trying to replicate other widgets like the datepicker and auto-suggest jQuery UI widgets, but mine has some requirements, so wanted to build from scratch.

Anyone got any suggestions on how I can accomplish this?

Thank you
0
tonelm54
Asked:
tonelm54
  • 2
1 Solution
 
Tom BeckCommented:
Struggling to follow your logic here. You are creating a div with the word "Hello" in it whenever one of the two text boxes has focus then removing the div whenever the text boxes lose focus. The click event on the created div never fires because the div is removed from the DOM as soon as you click on it (because the text box loses focus).

Is there a reason you need to create the divs dynamically rather then just have them hidden on the page?

Is there any reason not to give each textbook or div a common class so you can simply create event handlers for those classes? It would avoid looping over the text boxes (which doesn't make sense either since you are calling the function for each one separately anyway.)
$('#txtStartDate').makeDateTimePicker();
 $('#txtEndDate').makeDateTimePicker();

This update of your fiddle is still fairly useless, but it demonstrates my questions to you.

http://jsfiddle.net/c57uga1c/1/
0
 
tonelm54Author Commented:
Sorry, what Im trying to do is create an auto-complete box, which works the same as jQuery UI's but slightly different. What Ive got a problem with at the moment is the auto-complete box disappears when the textbox looses focus (which is correct), but if the mouse is in the auto-complete box then I don't want it to disappear.
0
 
Tom BeckCommented:
I thought I demonstrated how to do that with the jsfiddle I posted.

Anyway, here's an update to that fiddle with a little more functionality.

http://jsfiddle.net/c57uga1c/2/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now