user-a5567ffg
user-a5567ffg

Reputation: 225

jQuery assign value to Autocomplete and run code based on change(function()

Hopefully somebody can help me! For brevity, I'm trying to grab each value from a UI autocomplete widget and on submit run some code (in this case, an alert) based on which value they have selected (they may choose value after value).

So.. if they select 'Australia' from the autocomplete and hit submit: alert - "Australia". Then, if they select India from the autocomplete and hit submit: alert - "India" etc etc..

Here's my onchange function and full code in jsfiddle below:

 $('#topics').change(function(){

     if($(this).val() =='AU') {
           alert("Australia");
     }

     if($(this).val() =='PK') {
           alert("Pakistan");
     } 

     if($(this).val() =='IN') {
           alert("India");
     } 
});

http://jsfiddle.net/martsmithuk/PptYs/1/

It works PERFECTLY in Firefox, however when I try it IE(9) and Chrome - nothing, nada, the alert doesn't show up. Am I missing something really obvious? Please help!

Upvotes: 0

Views: 180

Answers (1)

user2377420
user2377420

Reputation:

if you check for browser and then in msie check event

$('#submit-button').click(function()

then instead of 'this' check for #topics value

i can't get the code to display properly here, I've updated your example

http://jsfiddle.net/PptYs/2/

Upvotes: 1

Related Questions