mardi 9 mai 2023

node.js handlebars express how to re-route on checkbox checked or unchecked

I am new to node.js and handelbars. I have searched everywhere and can't find a solution / example on how to re-route? (CRUD) when I check the checkbox.

i.e.

list.hbs snippet below

<label class="toggle">
   <input class="toggle-checkbox" type="checkbox" id="hide">
   <div class="toggle-switch"></div>
   <span class="toggle-label">Show all</span>           
</label>

When checkbox is checked

//list only active bookings for this vehicle
bookings.get('/activeonly/:ID', isLoggedIn, async(req, res) => {    
    const { ID } = req.params;
    const bookings = await pool.query('SELECT * FROM booking WHERE status <> "COMPLETED" and regnr = ?', [ID]);
    const bookingregnr = [ID];
    res.render('bookings/bookingslist', {bookings: bookings, bookingregnr});
    selectedRegnr = bookingregnr;
});

When check box is not checked

//list all bookings for this vehicle
bookings.get('/:ID', isLoggedIn, async(req, res) => {   
    const { ID } = req.params;
    const bookings = await pool.query('SELECT * FROM booking WHERE regnr = ?', [ID]);
    const bookingregnr = [ID];
    res.render('bookings/bookingslist', {bookings: bookings, bookingregnr});
    selectedRegnr = bookingregnr;
});

PLEASE HELP and THANK YOU

I have added the script below and can't move on from here other than out put on the console

    <script  type = "text/javascript">
        const toggles = document.querySelector("#hide");
        toggles.addEventListener('change',function(e){      
            if (toggles.checked){
                 console.log("Show completed");     
                
            }else{
                console.log("Hide completed");
                
            }
        });
    </script>



Aucun commentaire:

Enregistrer un commentaire