Solved

never stops alert

Posted on 2014-12-12
15
91 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery for Each 12 35
Client Validating 2 date fields, required & comparison 1 42
Javascript Form Change 5 31
Binding a Grid in Javascript 5 46
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

807 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