Results 1 to 2 of 2

Thread: Assign id upon elementCreate

  1. #1
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Assign id upon elementCreate

    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.
    HTML Code:
    <!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!

  2. #2
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Bump

    Ok I have gotten this far but script still seems to not be working can anyone help please?

    HTML Code:
    <script type="text/javascript">
    function createDIV()
    {
    var divID = prompt("Please Name Your New Div Box","");
    
    if(divID != null)
    document.createElement(false, divID);
    
    else (divID = true)
    var pallet = document.getElementById("Pallet");
    var divBox = document.createElement("div");
    divBox.setAttribute("id", var divID);
    divBox.setAttribute("style","width:50px; height:50px; background:#000;");
    Pallet.appendChild(divBox);
    }
    </script>
    
    <button onclick="createDIV();">Create DIV</button>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •