jennifer Jolie
jennifer Jolie

Reputation: 727

Alert a element after change in select box

I want alert a message after change or click on option in select box, but don't work for me.

What do i do?

Demo: http://jsfiddle.net/byw5H/

My code:

//Html Code
<select name="mainpage" size="6">
  <option value="1">11111111</option>
  <option value="2">22222222</option>
  <option value="3">33333333</option>
  <option value="4">44444444</option>
  <option value="5">55555555</option>
  <option value="6">66666666</option>
</select>​

//Js Code
$('select[name="mainpage"]').live('change',function(){
    alert('ok');
)}​

Upvotes: 1

Views: 3176

Answers (3)

Siva Charan
Siva Charan

Reputation: 18064

As others said, its a syntax error.

Apart from that, you can do this in other way too:-

$('select[name="mainpage"]').change(function(){
    alert('ok');
});​

Refer LIVE DEMO

Upvotes: 0

Mukesh Soni
Mukesh Soni

Reputation: 6668

syntax error -

$('select[name="mainpage"]').live('change',function(){
    alert('ok');
});

Upvotes: 0

epascarello
epascarello

Reputation: 207501

Open up the JavaScript console

syntax error
[Break On This Error]   

)}

That points to

$('select[name="mainpage"]').live('change',function(){
    alert('ok');
)}​  <-- HERE

You switched them! Correct order is })

$('select[name="mainpage"]').live('change',function(){
    alert('ok');
});

Upvotes: 2

Related Questions