Reputation: 4417
I have two radio buttons, click on one of them I will allow the input below and click on the other I allow the second input.
Here my HTML:
<fieldset data-role="controlgroup">
<input onclick="ChangeChoise(1);" type="radio" name="radio-choice" id="radio-choice-1" value="choice-1" checked="checked" />
<input id="Input1"/>
<input onclick="ChangeChoise(2);" type="radio" name="radio-choice" id="radio-choice-2" value="choice-2" />
<input disabled="disabled" id="Input2"/>
</fieldset>
At first the second input is not enabled, by clicking on the input ran the following function:
var ChoseDiv = 1;
function ChangeChoise(NumChoise) {
if (ChoseDiv == NumChoise)
return;
else
if (NumChoise == 1) {
$('#MyInput2').attr('disabled', 'disabled');
$('#MyInput1').attr('disabled', '');
}
else {
$('#MyInput1').attr('disabled', 'disabled');
$('#MyInput2').attr('disabled', '');
}
ChoseDiv = NumChoise;
}
It did not work
I tried also this way: $('#MyInput2').removeAttr('disabled');
And it did not work..
What am I missing??
Upvotes: 1
Views: 83
Reputation: 57309
jQuery Mobile has functions for enable/disable:
$('#Input1').textinput('disable');
$('#Input2').textinput('enable');
Here's a working example: http://jsfiddle.net/Gajotres/5N3vL/
And here's a official documentation: http://jquerymobile.com/demos/1.2.0/docs/forms/search/methods.html
Upvotes: 1