Content of a Function within a Modal

1

Comrades, I have a code that goes something like this:

JAVASCRIPT

function nfpa(){
    var resultado = "";
    resultado += "<div>";
    resultado += "CONTENIDO";
    resultado += "</div>";

document.getElementById('contenido').innerHTML = resultado;
     
}


function selector() {

    fo = document.getElementById('mySelect').value;
    document.getElementById('formula').innerHTML = "<b>"+fo+"</b>";
    document.getElementById('entrada').value = "";
    document.getElementById('salida').innerHTML = "";
    document.getElementById('procedimiento').innerHTML = "";
    productoSeleccionado = producto.find(x => x.n === this.value);
    tipoEl = document.getElementById('tipo');
    if (productoSeleccionado) {
        tipoEl.innerText = (productoSeleccionado.t === 'liq' ?
            'Indique la cantidad de LITROS de' + ' ' + fo + ': ' : 'Indique la cantidad de KILOS de' + ' ' + fo + ': ');
    } else {
        tipoEl.innerText = '';
    }

    tipoproducto = "";
    tipoproducto = productoSeleccionado.t;
    if (tipoproducto == "liq"){
        tipoproducto = " Litros de ";
    }
    else {
        tipoproducto = " Kilos de ";
    }

    var az ='';
    var ro ='';
    var am ='';
    var bl ='';

    az = productoSeleccionado.az;
    ro = productoSeleccionado.ro;
    am = productoSeleccionado.am;
    bl = productoSeleccionado.bl;
    bla = productoSeleccionado.bla;
    
    var azul = ""; 
    var rojo = "";
    var amarillo = "";
    var blanco = "";

var valores = [0,1,2,3,4]; 
    var riesgos = [
    "Sin riesgo",
    "Poco peligroso",
    "Peligroso",
    "Muy peligroso",
    "Mortal"];
    var inflamabilidad = [
    "No se Inflama",
    "Inflama a mas de 93°C",
    "Inflama a partir de 93°C",
    "Inflama a parir de 37°C ",
    "Inflama a parir de 25°C "];
    var reactividad = [
    "Estable",
    "Inestable en Caso de Calentamiento",
    "Inestable en caso de cambio quimico violento",
    "Puede Explotar en caso de choque o calentamiento",
    "Puede explotar subitamente"];
    var riesgoesp = [
        "Oxidante",
        "Corrosivo",
        "Radioactivo",
        "No Usar Agua",
        "Riesgo Biologico",
        "Ninguno"];

valores.forEach(function(elemento) {
    if(az == elemento) 
    azul = "Nivel de Riesgo: ["+elemento+"] " + riesgos[elemento];
    if (ro == elemento)
    rojo = "Inflamabilidad: ["+elemento+"] " + inflamabilidad[elemento];
    if (am == elemento)
    amarillo = "Reactividad: ["+elemento+"] " + reactividad[elemento];
    if (bla == elemento)
    blanco = "Riesgo Especial: " + riesgoesp[elemento];
});

    switch (bla) {
        case 0:
            // Oxidante
            var bl = "OXI";
            break;
        case 1:
            // Corrosivo
            var bl = "COR";
            break;
        case 2:
            // Radioactivo
            var bl = "<img alt= '' src='media/imagen/general/24px_simbolo_riesgo_radiactivo.png'> ";
            break;
        case 3:
            // No Usar Agua
            var bl = "<s>W</s>";
            break;
        case 4:
            // Riesgo Biologico
            var bl = "<img alt= '' src='media/imagen/general/24px_simbolo_riesgo_biologico.png'> ";
            break;
             case 5:
            // Riesgo Biologico
            var bl = "";
            break;
    }


    var rombo = "";
    
    rombo += "<tbody>";
    
    rombo += "<tr>";
    rombo += "<th><b>" + fo.toUpperCase() + "</b><br><a data-toggle='modal' data-target='#myModal3' name='NFPA' title='Cargar Explicacion sobre Rombo de Seguridad NFPA' href='#NFPA'><b>Rombo NFPA<b/> " + i + l + " </a><\/th>";
    rombo += "<\/tr>";
    rombo += "<tr>";
    rombo += "<td align=\"left\">";
    rombo += "<div class = \"rombo1\" >";
    rombo += "<div class = \"rombo2\" >";
    rombo += "<p>";
    rombo += "<img alt=\"NFPA 704.svg\" src=\"media\/imagen\/general\/NFPA_704.svg.png\"";
    rombo += "width=\"75\" height=\"75\" srcset=\"media\/imagen\/general\/NFPA_704.svg.png 1.5x, media\/imagen\/general\/NFPA_704.svg.png 2x\"";
    rombo += "data-file-width=\"600\" data-file-height=\"600\">";
    rombo += "<\/p>";
    rombo += "<\/div>";
    rombo += "<div class = \"rojo\" title=\"" + rojo + "\" \">"+ro+"<\/div>";
    rombo += "<div class = \"azul\" title=\"" + azul + "\">" + az +"<\/div>";
    rombo += "<div class = \"amarillo\" title=\"" + amarillo + "\" >" + am +"<\/div>";
    rombo += "<div class = \"blanco\" title=\"" + blanco + "\" >";
    rombo += "" + bl;
    rombo += "<\/div>";
    rombo += "<\/div>";
    rombo += "<\/td>";
    rombo += "<\/tr>";
    rombo += "<\/tbody>";

    
    rombo += "<!-- Modal 3 -->";
    rombo += "<div class=\"modal fade\" id=\"myModal3\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\">";
    rombo += "<div class=\"modal-dialog\" role=\"document\">";
    rombo += "<div class=\"modal-content\">";
    rombo += "<div class=\"modal-header\">";
    rombo += "<button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;<\/span><\/button>";
    rombo += "<h4 class=\"modal-title\" id=\"myModalLabel\">ROMBO NFPA<\/h4>";
    rombo += "<\/div>";
    rombo += "<div class=\"modal-body\">";

    rombo += "<div id='rombo_nfpa'></div>";
    rombo += "<\/div>";
    rombo += "<div class=\"modal-footer\">";
    rombo += "<button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Cerrar<\/button>";
    rombo += "<\/div>";
    rombo += "<\/div>";
    rombo += "<\/div>";
    rombo += "<\/div>";

   
    document.getElementById('nfpa').innerHTML = rombo;
    document.getElementById("mySelect").value = sup;

}

My query is how I can make that when I make the call to MODAL3 I can show the content of the function nfpa () I tried with an onload and onclick but it loads in the page the content of nfpa () and not inside the modal .

I have a button that loads the contents of several functions ie objects load function objects () extension loads the function extension () but there are other functions like the example where I need to load the content of nfpa () inside a modal to avoid leave the content that is being read.

    
asked by Jose M Herrera V 13.04.2018 в 01:05
source

0 answers