Link to home
Start Free TrialLog in
Avatar of joyacv2
joyacv2Flag for Puerto Rico

asked on

never stops alert

<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?
Avatar of Gary
Gary
Flag of Ireland image

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?
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
Avatar of joyacv2

ASKER

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?
Avatar of joyacv2

ASKER

i am using safari for mac
Avatar of joyacv2

ASKER

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
Avatar of joyacv2

ASKER

in chrome works well, but in safari never stops
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?
Must be a Safari bug, happens for me too,
Yep it's a bug in Safari
Possible solution is to unbind the event before the alert and then rebind it after the alert.
Avatar of joyacv2

ASKER

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?
The blur is fine but remove the alert so you don't end up in circles with a focus/blur firing.
Avatar of joyacv2

ASKER

yes, but this will cause that my code repeat forever to the database
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
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
dont use alert in blur... do whatever you need here but just dont use alert :)

or use something like this...

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