I need to know how to save more than one checkbox field option in a table field in the database. This is the way I form the chechkbox (they are the days of the week)
h4 Dia de la Semana
label.checkbox-inline
input#checkboxdo(type='checkbox',name='checkboxdia', value='0',class='dia')
| D
label.checkbox-inline
input#checkboxl(type='checkbox',name='checkboxdia', value='1',class='dia')
| L
label.checkbox-inline
input#checkboxma(type='checkbox',name='checkboxdia', value='2',class='dia')
| M
label.checkbox-inline
input#checkboxmi(type='checkbox',name='checkboxdia', value='3',class='dia')
| M
label.checkbox-inline
input#checkboxju(type='checkbox',name='checkboxdia', value='4',class='dia')
| J
label.checkbox-inline
input#checkboxvi(type='checkbox',name='checkboxdia', value='5',class='dia')
| V
label.checkbox-inline
input#checkboxsa(type='checkbox',name='checkboxdia', value='6',class='dia')
| S
.modal-footer
button.btn.btn-default(type='button', data-dismiss='modal',style='margin-left:0px;width:100px;') Cerrar
button#btnAgregarRecordatorio.btn.btn-primary(type='button',style='margin-left:10px;width:100px;',onclick="insertar_recordatorio()") Guardar
the way in which the values are collected is like this
function insertar_recordatorio(){
const usu = document.querySelectorAll('input[type=checkbox]:checked');
if( $('#checkboxdo').prop('checked') ) {
var dia=$('#checkboxdo').val();
} if( $('#checkboxl').prop('checked') ) {
var dia=$('#checkboxl').val();
}if( $('#checkboxma').prop('checked') ) {
var dia=$('#checkboxma').val();
}if( $('#checkboxmi').prop('checked') ) {
var dia=$('#checkboxmi').val();
}if( $('#checkboxju').prop('checked') ) {
var dia=$('#checkboxju').val();
}if( $('#checkboxvi').prop('checked') ) {
var dia=$('#checkboxvi').val();
}if( $('#checkboxsa').prop('checked') ) {
var dia=$('#checkboxsa').val();
}
onAgregar(titulo,mensaje,hora,dia,CorreoExtra);
}
and that's how the insert is made
exports.insert = function(g, done) {
var sqlstring = 'INSERT INTO citas(pk,dia) VALUES(uuid_generate_v1mc(),$1) RETURNING pk';
var sqlvalues = [g.dia];
mpg.query(sqlstring, sqlvalues, function(err,result){
mglobal.validarResultQueryInsert(err,result,nombre_modulo,sqlstring,sqlvalues, function(resvalid){
if(resvalid.exito && result.rows.length > 0)
resvalid.pk =result.rows[0].pk;
done(resvalid);
});
});
}