Mike
Mike

Reputation: 980

Why isn't drop down changing based on other value?

I'm not sure why this isn't working. Anyone care to take a stab?

I have a form with the below. When the user selects the "disabled" option in #frmcomments, I'd like #frmstatus to change to the option value of private.

<label for="type">Comments:</label>
<select class="sort-select" id="frmcomments" name="frmcomments">
    <option value="enabled">Allow Comments</option>
    <option value="disabled">No Comments</option>
</select>



<label for="type">Status:</label>
<select class="sort-select" id="frmstatus" name="frmstatus">
    <option value="public">Anyone can see</option>
    <option value="private">Only I can see</option>
</select>

I'm using the following jquery, but it's failing?

$('#frmcomments').change(function() {
    var thistype = $(this).find(":selected").val();

    if(thistype=="disabled") {
        $("#frmstatus").val("private");
    }

    return false; 
});

Upvotes: 0

Views: 56

Answers (3)

Yorgo
Yorgo

Reputation: 2678

var thistype = $(this).find(":selected").val();

try this

var thistype = $(this).val();

Upvotes: 0

thecodeparadox
thecodeparadox

Reputation: 87073

$('#frmcomments').change(function() {
    var thistype = $(this).val();

    if(thistype=="disabled") {
        $("#frmstatus").val("private").change();
    }
    return false; 
});

Upvotes: 0

Ropstah
Ropstah

Reputation: 17804

Check your thistype value. You should be able to call val() on the select and you shouldn't have to call .find(":selected") to get the selected list item.

Upvotes: 1

Related Questions