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
-
1Yes it is possible. I don't have any answer till I don't see any code.Koste– Koste2012-07-05 14:09:31 +00:00Commented 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.itsamemario– itsamemario2012-07-05 14:11:17 +00:00Commented Jul 5, 2012 at 14:11
Add a comment
|
6 Answers
A quick demonstration: http://jsfiddle.net/mblase75/vZacx/
$('#picker').on('change', function() {
$('#' + $(this).val()).prop('disabled', false)
.siblings().prop('disabled', true);
});
Comments
Something like this maybe :
$("select").on('change', function() {
$('button').prop('disabled', this.value==='EnabledOptionValue'?false:true);
});
FIDDLE
Comments
$('select').change(function(){
var theVal = $(this).val();
switch(theVal){
case '0':
$('#theButton').prop('disabled', true);
break;
case '1':
$('#theButton').prop('disabled', false);
break;
}
});
Comments
<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>

see jsFiddle