Solved

never stops alert

Posted on 2014-12-12
15
86 Views
Last Modified: 2014-12-12
<script>

$("input").blur(
             function (event) {
                 alert("test");
             }
         );

</script>

I am using this script in a jquery mobile page, when i leave an input box, this never stops sending the alert message, any idea?
0
Comment
Question by:joyacv2
  • 6
  • 6
  • 2
  • +1
15 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40496819
I'm guessing the alert is causing focus to be lost and then focus is changed again or something along those lines
Do you have some real code to look at?
0
 
LVL 9

Expert Comment

by:WebDevEM
ID: 40496833
Hi,

I set up a Fiddle (http://jsfiddle.net/webdevem/43j66esh/) to test this - At first I thought it was going to trigger because "input" would attach to all inputs on the page and no matter where the page focus is, it would be blurred from another input.

Odd thing is, it only triggered once for me.  What browser/version were you using?  This worked fine for me in Chrome for Mac
0
 
LVL 1

Author Comment

by:joyacv2
ID: 40496834
ok,

is a bunch of code that works with php, and for testing needs to many configuration files, do you know any alternative to blur in this case?
0
 
LVL 1

Author Comment

by:joyacv2
ID: 40496840
i am using safari for mac
0
 
LVL 1

Author Comment

by:joyacv2
ID: 40496845
i want to when the user leaves an input, an ajax is called, but i never passed the alert test that i always do before continue
0
 
LVL 1

Author Comment

by:joyacv2
ID: 40496847
in chrome works well, but in safari never stops
0
 
LVL 58

Expert Comment

by:Gary
ID: 40496867
Do you have a test page to look at?
When you leave the input is it go to another input?
What is the purpose of the alert - do you really need it or is it just for testing?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 58

Expert Comment

by:Gary
ID: 40496876
Must be a Safari bug, happens for me too,
0
 
LVL 58

Expert Comment

by:Gary
ID: 40496883
Yep it's a bug in Safari
Possible solution is to unbind the event before the alert and then rebind it after the alert.
0
 
LVL 1

Author Comment

by:joyacv2
ID: 40496888
Hi Gary,

The test on the WebDevEM is perfect for the discussion. This is exactly what is happening to me. Let me try to explain my purpose,

I want to update a database after an user leaves an input using ajax, so i found that blur will give me the method for run the code after the user leaves the input, do you know any other solution?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40496905
The blur is fine but remove the alert so you don't end up in circles with a focus/blur firing.
0
 
LVL 1

Author Comment

by:joyacv2
ID: 40496910
yes, but this will cause that my code repeat forever to the database
0
 
LVL 9

Expert Comment

by:WebDevEM
ID: 40496922
I think I see Gary's point... the alert itself may be changing the focus.  Try removing it or replacing it with something like changing the background color of something, or appending text to another element so you know its there.

I'll update the Fiddle with an example
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40496924
No, it's the alert itself which is causing the multiple alerts, once you remove that then it will only fire once.

And forget http:#a40496883 - just tested and it still keeps firing.
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40496926
dont use alert in blur... do whatever you need here but just dont use alert :)

or use something like this...

$("#msg").htlm("message here...");
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now