Select value check

+2 eric bruce · November 4, 2014
ok so i got a select drop down 

<select id="monster1">
<option value="">Select</option>
<option value="Acid Blobs">Acid Blobs</option>

<button type="submit" id="button">Click!</button>

pretty simple not much 2 it 

what i need to do is check this drop down list and check the value 

this is the java i am playing with atm 

if ($('#monster1').val() == 'Acid Blobs')
{alert('yes')} else 

iv read around a bit and found a few ways to get the value i know the .val() works with a text input box first time iv tried to match something with a drop down and it fails 

i tried this a good few ways but just worked a 16 hour shift and ima give up for now >.< soooo if you know how to fix please help ty =)

Post a Reply


Oldest  Newest  Rating
0 Predrag Kostic · November 15, 2014
This is what I learned at codecademy yesterday, it's not selectors but input:
$(document).ready(function() {
    $('button').click(function() {
        var toAdd = $("input[name=message]").val();

MESSAGE: <input type="text" name="message" value="Type your text here!">

Dunno how to do it with selectors though.
  • 1



A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.