I want to create tabs from some data consulted in the database, in each tab you will have checkbox
which I want to have an action onChange
but I can not insert the tag script
in a chain string
function GenerarPestanias() {
var pestanias = '<ul class="nav nav-tabs" role="tablist">';
$.each( todoFunciones, function( i, j ){
if(i!=0){
if(j.id_padre==0){
var ident = j.titulo.toLowerCase().replace(/\s/g,'');
$.each( todoFunciones, function( x, y ){
if(y.id_padre==j.id){
}
});
pestanias += ''+
'<li><a href="#'+ident+'" data-toggle="tab" aria-expanded="true">'+j.titulo+' '+
'<input id="menu_'+ident+'" name="menu_'+ident+'" data-info="general" name="my-checkbox" type="checkbox" data-toggle="toggle" data-on="<span class=\'fa fa-power-off\'></span>" data-off="<span class=\'fa fa-power-off\'></span>" data-onstyle="success" data-offstyle="danger">'+
'</a>'+
'</li>'+
'<script type="text/javascript">'+
'</script>';
}
}
});
pestanias += '</ul>';
return pestanias;
}
At the end of the script tag it throws me an error.
I do not know if it is the right way, if there is another and better, welcome it will be.
Update 1:
I would like each checkbox to contain something like this:
$('#checkbox').on("change", function(){
if($(this).prop("checked") == true){
alert(true);
}else{
alert(false);
}
});
Update 2:
Do not explain what I want each checkbox to do, because as I said above I create tabs with bootstrap ( as here ) From a query to the BD, the table is composed as follows:
CREATE TABLE public.funciones
(
id integer NOT NULL DEFAULT nextval('funciones_id_seq'::regclass),
id_padre integer NOT NULL,
icono character varying(255) NOT NULL,
link character varying(255) NOT NULL,
titulo character varying(255) NOT NULL,
status boolean NOT NULL
)
Those that contain id_padres = 0
are the tabs, those that contain id_padres > 0
are children which I want to appear within the content of each tab as well as checkbox.
Here is an example of a query (typo json) to the table
todoFunciones =
[
{
"id": 1,
"id_padre": 0,
"icono": "fa fa-dashboard fa-fw",
"link": "/",
"titulo": "Tablero",
"status": true
},
{
"id": 2,
"id_padre": 0,
"icono": "fa fa-tasks fa-fw",
"link": "#",
"titulo": "Procesos",
"status": true
},
{
"id": 3,
"id_padre": 2,
"icono": "fa fa-list-ol fa-fw",
"link": "/lotes",
"titulo": "Lotes",
"status": true
},
{
"id": 4,
"id_padre": 2,
"icono": "fa fa-eraser fa-fw",
"link": "/limpieza",
"titulo": "Limpieza",
"status": true
},
{
"id": 5,
"id_padre": 2,
"icono": "fa fa-stop fa-fw",
"link": "/paradas",
"titulo": "Paradas",
"status": true
},
{
"id": 6,
"id_padre": 2,
"icono": "fa fa-wrench fa-fw",
"link": "#",
"titulo": "Mantenimiento",
"status": true
}
]
;