0

Is it possible to enable or disable a button which is in a form, based on a select (drop down) option which isn't in a form? I don't have any code, I will have it (or not) based on your answer to my question :D

2
  • 1
    Yes it is possible. I don't have any answer till I don't see any code. Commented Jul 5, 2012 at 14:09
  • No, no, guys, easy, I don't expect you to work for me, just wanted to know is it possible. Commented Jul 5, 2012 at 14:11

6 Answers 6

9

A quick demonstration: http://jsfiddle.net/mblase75/vZacx/

$('#picker').on('change', function() {
    $('#' + $(this).val()).prop('disabled', false)
        .siblings().prop('disabled', true);
});​
Sign up to request clarification or add additional context in comments.

Comments

2

Just put your code disabling/enabling the button in the change event of the drop down.

Comments

2

Something like this maybe :

​$("select")​.on('change', function() {
    $('button').prop('disabled', this.value==='EnabledOptionValue'?false:true);
})​;

FIDDLE

Comments

1
$('select').change(function(){
  var theVal = $(this).val();
  switch(theVal){
    case '0':
      $('#theButton').prop('disabled', true);
      break;
    case '1':
      $('#theButton').prop('disabled', false);
      break;
  }
});

Working jsFiddle

Comments

1
<script type="text/javascript">
$(document).ready(function() {
$("#demo_button").button({icons: {secondary: "ui-icon-info"}});
$("#demoSelect").addClass("ui-state-default ui-corner-all");
var demoSelectValue = $("#demoSelect").val();
if (demoSelectValue == "0") {
$("#demo_button").button("disable")
}
$("#demoSelect").change(function(){
if($(this).val() == "0"){
$("#demo_button").button("disable")
}
else {
$("#demo_button").button("enable")
}
});
});
</script>

HTML:

<select name="demoSelect" id="demoSelect">
<option value="0">No</option>
<option value="1">Yes</option>
</select>
<button id="demo_button" style="float:right;">button</button>

jsFiddle demo

see jsFiddle

Comments

0
$('#Select').change(function(){
    //Some condition
    $('#Button').attr('disabled','disabled');
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.