jquery find out of selected option has value or not?

Discussion in 'jQuery' started by EricBruggema, Nov 13, 2012.

  1. #1
    Hi there,

    Does anyone know a easy way to find out if the selected option has a value? as .val returns in this case the text and i'm looking for a way to let jquery tell me that the option value is empty.
     
    EricBruggema, Nov 13, 2012 IP
  2. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #2
    Mh...found something on stackoverflow that might help you out

    http://stackoverflow.com/questions/154059/what-is-the-best-way-to-check-for-an-empty-string-in-javascript
    Code (markup):
     
    GMF, Nov 13, 2012 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    Well i've found out that if you don't use the value="" part in option, jQuery will return the text as the value. Only thing to do is add value="" and the value stays empty!
     
    EricBruggema, Nov 14, 2012 IP