Skip to content
Advertisement

.blur() sound notifications

I have two text boxes whose values are ‘yes’ and ‘no’. When I type ‘yes’ in the first text box, it beeps and the same should happen with the remaining text box. The sound should play only once when I enter the correct value in the corresponding text boxes.

In my case, the sound is repeating again and again… I don’t know what might be the cause.

JavaScript

Advertisement

Answer

The sound is playing more than once because you’re checking the blur event, so every time the user blurs out of the box the sound will replay as long as the correct answer in in the box. Instead you should check for keyup event.

Example:

JavaScript

JSFiddle demo

http://jsfiddle.net/7ahpgt5s/

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement