Solved

never stops alert

Posted on 2014-12-12
15
94 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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
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 55

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
This article discusses how to implement server side field validation and display customized error messages to the client.
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)

691 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