Jason
Jason

Reputation: 396

Dropdown that enable/disable button

I'm trying to have a dropdown menu that enable/disable button, and I'm following this example

but it's 4 years old and the function doesn't seems to work on my xhtml page.

Any help would be appropriated

Upvotes: 0

Views: 95

Answers (2)

Stan Shaw
Stan Shaw

Reputation: 3034

HTML:

<select id='ddlToggle'>
    <option Value='1'>ON</option>
    <option Value='0'>OFF</option>
</select>
<input type='button' id='btn1' Value='Hello' />

JQuery:

$("#ddlToggle").on("change", function(){
    $("#btn1").prop("disable", $(this).val() == "0");
});

Upvotes: 0

Zander
Zander

Reputation: 1086

Here is a live demo: http://jsfiddle.net/txrkrgms/

using .prop() method on the button you like when the select is .change().

$("select").change(function() {
    if($(this).val() == "on")
        $("button").prop("disable", false);
    else
        $("button").prop("disable", true);
});

Hope is what you are searching for.

Upvotes: 2

Related Questions