In my form i have two checkboxes.But i can check both the checkboxes.How can i disable the other checkbox if one checkbox is checked.
this is how i gave my checkboxes
<label><h4><b>Payment Type</b></h4></label>
<ion-checkbox id="isChecked1" name="isChecked1" ng-model="isChecked1">Immediate Payment</ion-checkbox>
<ion-checkbox id="isChecked2" name="isChecked2" ng-model="isChecked2">Schedule Payment</ion-checkbox>
I'm not getting why you're not using a radio button, but here is a pretty easy example using only javascript.
Working fiddle:
HTML:
<input type="checkbox" id="isChecked1">Immediatly</input>
<input type="checkbox" id="isChecked2">Later</input>
Javascript:
var chk1 = document.getElementById("isChecked1");
var chk2 = document.getElementById("isChecked2");
chk1.onchange = function() {
chk1.checked ? chk2.disabled = true : chk2.disabled = false;
};
chk2.onchange = function() {
chk2.checked ? chk1.disabled = true : chk1.disabled = false;
};
However, please take in consideration using radio buttons for such a task. I'm pretty sure that they were invented for a reason :)
Also, my example is in pure javascript because I'm not very familiar with angularjs or whatever you're using. In any case, you should easily be able to accomplish it using javascript only without affecting your scripts that much.
Edit:: Moreover, according to your IDs, this script should already be working for you, regardless angularjs or not
Sorry.. To made it simple you can use radio button..
Else..
use javascript like this,
Check1 = document.getElementById("check1");
Check2 = document.getElementById("check2");
if(Check1.checked)
Check2.checked = false;