gnozer44
gnozer44

Reputation: 25

JQuery - Item selected

I want to get the item selected in my select tag

Here is my HTML code :

<label for="mail">Envoyer mail :</label>
<select name="mail" id="selectmail">
   <option value="1">Case n°1</option>
   <option value="2">Case n°2</option>
   <option value="3">Case n°3</option>
</select>
<input type="button" id="sendmail" name="mail" value="Envoyer"><a href=""></a>

And here is my JQuery function :

$('#sendmail').click($.post(
   'adressepagetraitement.php', {
      v:$('#selectmail').val()
   },
   function(data)
   {
      alert('message envoyé');
   }
));

The problem :

TypeError: handleObj.handler.apply is not a function

.apply( matched.elem, args );

Upvotes: 0

Views: 78

Answers (3)

Suraj Rawat
Suraj Rawat

Reputation: 3763

You forgot to wrap your code with anonymous function !

 $('#sendmail').click(function(){$.post(
    'adressepagetraitement.php', {
     v:$('#selectmail').val()
  },
  function(data)
    {
     alert('message envoyé');
  }}
  ));

Upvotes: 0

MarkSkayff
MarkSkayff

Reputation: 1374

I think you are failing there in the way you pass the handler to click. You should do it like this:

$(elementid).click(function(){ //place your post code here });

Place the $.post inside the function(){} braces and you'd be alright.

Upvotes: 1

Ryan
Ryan

Reputation: 14649

Use the on() method passing in the 'change' event.

var VALUE;
$('#selectmail').on('change', function() {
  console.log("This is the selected value " + this.value)
  VALUE = this.value;
});
$('#sendmail').click(...) {


});

Upvotes: 0

Related Questions