Solved

never stops alert

Posted on 2014-12-12
15
93 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
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
 
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 53

Expert Comment

by:Huseyin KAHRAMAN
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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)

738 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