Hayley
Hayley

Reputation: 37

jQuery blur and click events doubling up

My code: http://jsfiddle.net/hayleyeaston/nkfms/4/

I am putting together a postcode lookup where a user inputs a postcode and then clicks a button to trigger a postcode search. I've got an event handler on the click but I also want to add one for blur on the input field, in the case where a user might enter their postcode but not actually click 'Lookup'. This is to ensure that a postcode search occurs before the user tries to submit the whole form.

My problem is when a user enters a postcode and clicks the 'Lookup' button I get both blur and click events running. I see 'search postcode' in my console log twice. How can I fix this so that the blur only occurs if the user didn't click the 'Lookup' button.

My code is in the JSFiddle link above. Please can anyone help, its been driving me crazy for the last few days. It has occurred to me to check on form submit if the postcode search has occurred, but ideally if possible I'd like to fix the blur/click issue. Thanks.

Upvotes: 0

Views: 117

Answers (1)

Grim...
Grim...

Reputation: 16953

Remove the click() event - you don't need it.

My fiddle: http://jsfiddle.net/Grimdotdotdot/UKGYN/

Upvotes: 1

Related Questions