0

I am trying to get a value of a select box, using onchange, but when I use this.val

<select name="type" name="auctionlength" onchange="listing_type();" id="listingtype" class="form-control">
   <option><?php echo System::translate("Choose an option"); ?></option>
   <option value="auction"><?php echo System::translate("Auction"); ?></option>
   <option value="buy"><?php echo System::translate("Buy It Now"); ?></option>
</select>

and the following is my function:

var listing_type = function()
{
    console.log(this.val);
}

I have tried the following instead:

this.val();
this.value()
this.value
$(this).val()
$(this).value()

But still not working?

4334738290
  • 393
  • 2
  • 19

1 Answers1

0

Like this:

HTML

<select name="type" name="auctionlength" onchange="listing_type(this.value);" id="listingtype" class="form-control">
   <option><?php echo System::translate("Choose an option"); ?></option>
   <option value="auction"><?php echo System::translate("Auction"); ?></option>
   <option value="buy"><?php echo System::translate("Buy It Now"); ?></option>
</select>

JS

function listing_type(value){
    console.log(value);
}
derp
  • 2,300
  • 13
  • 20