skip to Main Content

I am trying to record that the user has checked the checkbox, and am not sure where to start. this is using the ionic framework with vanilla JS.

I have the tag for a checkbox:

<ion-list>
       <ion-checkbox id="Email-check">Email</ion-checkbox>
<ion-list>

A variable that is refering to the ID in the tag:

const emailCheckbox = this.querySelector('#Email-check');
And an empty function:

function storeemailCheck(){
        
    }

2

Answers


  1. As per the documentation there is a checked attribute on the ion-checkbox element, so you should be able to target that attribute using emailCheckbox.checked inside your function.

    function storeemailCheck(){
        const emailCheckbox = this.querySelector('#Email-check');
        if (emailCheckbox.checked){
            // do something here..
        }
    }
    
    Login or Signup to reply.
  2. Use ngModel Template Driven forms.

    <ion-checkbox slot="end" color="primary" [(ngModel)]="emailCheckbox" (ngModelChange)="someFunctionnInTs()"  ></ion-checkbox>
    

    emailCheckbox will be true if user checks the checkbox and false if unchecked.If you need a change event you can call ngModelChange

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search