View Full Version : displaying checkbox on the screen

12-31-2011, 01:56 PM
Hi friends,
I have a dropdown menu,when i select one item from the dropdown menu,i want a checkbox to be created on the screen.How do i achieve this?

Thank You

12-31-2011, 03:21 PM
Use document.createElement() and element.appendChild() to manipulate the DOM tree...

Philip M
12-31-2011, 04:43 PM
No need to "manipulate the DOM tree". Use this:-

<select id = "mysel" onchange = "showbox()">
<option value = 0>Select an option....</option>
<option value = 1>Option One</option>
<option value = 2>Option Two</option>
<option value = 3>Option Three</option>

<div id = "boxcontainer" style="display:none">
Check this box <input type = "checkbox" id = "chk1">

<script type = "text/javascript">

function showbox() {
document.getElementById("boxcontainer").style.display="none"; // hide the checkbox
document.getElementById("chk1").checked = false; // uncheck if a different option is chosen
var val = document.getElementById("mysel").selectedIndex;
if (val == 3) { // or whatever option applies
document.getElementById("boxcontainer").style.display="inline"; // show the checkbox


Quizmaster: What is a chaffinch?
Contestant: It is a measurement