devinrayolsen
05-25-2008, 07:49 PM
Hi i have this little project that creates a div box upon clicking a button.
However I would like to make it so when a user clicks this "Create DIV" button an alert window pops up and asks them to name the new div box before it creates the div box. What ever the user names the div box it will be set as the div boxes id. Any idea on how to do this?
Here is my code thus far.
<!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>Untitled Document</title>
<style>
html,body {
margin:0;
}
#Pallet {
width:100%;
height:740px;
border:#000 thin solid;
overflow:scroll;
background:#F7F5E6;
}
#newDiv {
width:50px;
height:50px;
background:#FFFFCC;
color:#FFFFFF;
}
</style>
</head>
<body>
<div id="Pallet">
</div>
<script type="text/javascript">
function insertDIV()
{
//Create Div Boxes
var Pallet = document.getElementById("Pallet");
var divBox = document.createElement("div");
Pallet.appendChild(divBox);
}
</script>
<button onclick="insertDIV();">Create DIV</button>
</body>
</html>
Thanks everyone!
However I would like to make it so when a user clicks this "Create DIV" button an alert window pops up and asks them to name the new div box before it creates the div box. What ever the user names the div box it will be set as the div boxes id. Any idea on how to do this?
Here is my code thus far.
<!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>Untitled Document</title>
<style>
html,body {
margin:0;
}
#Pallet {
width:100%;
height:740px;
border:#000 thin solid;
overflow:scroll;
background:#F7F5E6;
}
#newDiv {
width:50px;
height:50px;
background:#FFFFCC;
color:#FFFFFF;
}
</style>
</head>
<body>
<div id="Pallet">
</div>
<script type="text/javascript">
function insertDIV()
{
//Create Div Boxes
var Pallet = document.getElementById("Pallet");
var divBox = document.createElement("div");
Pallet.appendChild(divBox);
}
</script>
<button onclick="insertDIV();">Create DIV</button>
</body>
</html>
Thanks everyone!