Search code examples
javascripthtmlcheckboxpopupwindow

How can i make a pop-up window with checkboxes using javascript?


I am trying to make a button that opens a pop-up window when it is clicked. It is working, but I would like to add a pop-up window that has three checkboxes. It is an assignment for school, so I can't use any other languages than HTML5, CSS and JavaScript. Is this possible? This is the HTML code:

<script language="JavaScript" src="prijsvraag.js"></script>
<input type="button" onclick="prijsvraagknop()" value="Prijsvraag"></button>

This is the js code

function prijsvraagknop(){
var naam = window.prompt("Jouw naam:")
var jouw_antwoord = window.prompt("Jouw reactie:")

if (document.getElementById('B').checked) {
    alert("Hoera " + NaamVar + "! Je hebt het antwoord goed. Er doen nog meer kinderen mee. Je kunt daarom over een maand op deze pagina lezen of je de hoofdprijs gewonnen hebt.");
    }
else {
    alert("Helaas " + NaamVar + ". Je hebt het antwoord fout. Je maakt geen kans op de hoofdprijs.");
    }   

Solution

  • Here is one example.The html code consist of checkboxes shown below.

    <input type="button" id="popupbutton" onclick="popup(this)"/>
        <ul id="checkBundle">
            <li><label><input type="checkbox" />test1</label>
            <li><label><input type="checkbox" />test2</label>
            <li><label><input type="checkbox" />test3</label>
            <li><label><input type="checkbox" />test4</label>
         </ul>
    

    The javascript is below

      function popup() {
           var popwindow = document.getElementById("checkBundle");
           if (popwindow.style.display === "none") {
               popwindow.style.display = "block";
          } else {
                popwindow.style.display = "none";
            }
       };