0

i am starting programming in html-css-javascript and the thing is i have a main.html that has a button to open a popup (popup.html).

The problem is in main.html i have a checkbox and i want to get the checkbox's value from the popup.

Is there any way to get the value if i stand in popup.html?

From main.html i can do

var pecho = document.getElementById("pechoButton");
alert(pecho.checked);

but i want to do the same from popup.html

Thanks

main.html:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Gim Web</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<script src="./scripts.js"></script>
</head>
<body>
<div id="container">
  <div id="encabezado"><img src="Images/banner.jpg" width="940" height="300" alt="banner" /></div>
  <div id="cuerpo">
    <div id="musculos">
      <div id="pecho">
        <p>Pecho <input name="pecho" type="checkbox" id="pechoButton"/></p>
      </div>
      <div id="tricep">
        <p>Tricep <input name="Guardar" type="button" onclick="saveData()"/></p>
</div>
    </div>
  </div>
  <div id="pie">Content for  id "pie" Goes Here</div>
</div>
</body>
</html>

popup.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Datos:</title>
<script src="./scripts.js"></script>
</head>
<body onload="getDatos()">
</body>
</html>

scripts.js:

// JavaScript Document
function saveData(){
    var pecho = document.getElementById("pechoButton");
    alert(pecho.checked)
    window.open("popUpResult.html", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
}

function fechaHoy(){
    var meses = new Array ("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
    var diasSemana = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
    var fecha=new Date();
    var result = diasSemana[fecha.getDay()] + ", " + fecha.getDate() + " de " + meses[fecha.getMonth()] + " de " + fecha.getFullYear();
    return(result);
}

function resultados(){
    var msj = fechaHoy()  + "\n"
    /*if (pecho.checked = "true")
    {
        msj = msj + "Pecho \n"
    }*/
    return(msj);
}

function getDatos(){
    document.write(resultados());
}
LPS
  • 581
  • 3
  • 8
  • 17

1 Answers1

1

You can use sessionStorage and store the value of the checkbox that way: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

Then check the value in the popup.

ilia
  • 329
  • 3
  • 11