Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Switching toggle-wrap based on database value

Currently I have a toggle-wrap switch in my update page. As of now in my database, the value for this can be Null, No and Yes. So when the user enters the page, I want this switch to be off if the database value is in Null or no and switched on if the database value is Yes in the database. I’ve tried the following to enable the toggle but it does not toggle on when the data value in my database is Yes.

View Class:

<label class="control-labels mr-4">Lead Gen?</label>
                    <div class="toggle-wrap tg-list-item">
                        <input class="tgl tgl-light" id="leadgen" name="leadgen" type="checkbox" 
                        <?php echo ($listing[0]['leadgen'] == 'Yes' ? 'enabled':'disabled'); ?> />
                        <label class="tgl-btn" for="leadgen"></label>
                    </div>

Doing a var_dump on $listing[0]['leadgen'] gave me string(3) "Yes" But the switch still doesn’t turn on

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Instead of using ‘enable’ and ‘disable’ have a look at checked. Your code would become:

<label class="control-labels mr-4">Lead Gen?</label>
                    <div class="toggle-wrap tg-list-item">
                        <input class="tgl tgl-light" id="leadgen" name="leadgen" type="checkbox" 
                        <?php echo ($listing[0]['leadgen'] == 'Yes' ? 'checked' : ''); ?> />
                        <label class="tgl-btn" for="leadgen"></label>
                    </div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading