Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2017
    Posts
    197
    Thanks
    2
    Thanked 0 Times in 0 Posts

    last option value

    I trying to get the value of the last option of a select.
    I've tried
    Code:
    var lastValue = parseInt(document.getElementById("IdOfElement").options.lastValue);
    alert(lastValue);
    gives me NaN, and
    Code:
    var lastValue = $('#IdOfElement option:last-child').value();
    alert(lastValue);
    No alert.

  2. #2
    Regular Coder
    Join Date
    Aug 2017
    Posts
    197
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Got it working.
    Code:
    var theSelect = document.getElementById('SelectId');
    var lastValue = theSelect.options[theSelect.options.length - 1].value;


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •