Link to home
Start Free TrialLog in
Avatar of Coast Line
Coast LineFlag for Canada

asked on

Create New Div's with styles inside the Div

My Question here, I am using Javascript Modal Window an Old Modal Window of Javascript not using the jquery!

Now i can get the data from the modal window bt when i clik "Add", it does not populate my DIV which i have declared inside the Page!

so here is the code

with this code i am getting error
theDiv.appendChild is not a function
Line 11
function getMyValues(){
	var show = window.showModalDialog("abc.cfm", window,"center=yes;dialogWidth:900px:dialogHeight:800px"); 
	if(show!=undefined) { 
		var aid = show.SID;
		var arrID = aid.split(',');
		for (var j=0; j<arrID.length; j++){
			var theDiv = 'projectsList'; -- This is my parent Div name
			var newNode = document.createElement('div');  -- I am trying to create a New Div inside the Div of the parent with the Styles, also want to pass asa hidden field with the each div which is being created inside the parent div
			newNode.innerHTML = arrID[j]; 
			theDiv.appendChild(newNode) 
		}
		
	}
}

Open in new window

Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

var theDiv = document.getElementById('projectsList'); // -- This is my parent Div ID
Avatar of Coast Line

ASKER

ok it worked, but it added only 1 record and neither the style attribute if i need to have something like

a border to doiv with width of 100 and an image icon if possible so when clicked will delete that DIV tag from the parent div

Please guide me

Thanks for the Prompt response mplungjan
Not sure I follow

You mean something like this
function getMyValues(){
  var show = window.showModalDialog("abc.cfm", window,"center=yes;dialogWidth:900px:dialogHeight:800px"); 
  if(show!=undefined) { 
    var aid = show.SID;
    var arrID = aid.split(',');
    var theDiv = document.getElementById('projectsList');
    alert('adding ' + arrID.length + ' elements'); // what does this alert?
    for (var j=0; j<arrID.length; j++){
       // I am trying to create a New Div inside the Div of the parent with the Styles, 
       // also want to pass as a hidden field with the each div which is being created inside the parent div
      var newNode = document.createElement('div');
      newNode.style.border='1px solid black';  
      newNode.innerHTML = arrID[j] + '<img src="somegif.gif" onclick="var el = this.parent; el.parent.removeChild(el)" />'; 
      theDiv.appendChild(newNode); 
    }
    
  }
}

Open in new window

yes the way i am doing is bit different but same as above

i am using the following as:

var newNode = document.createElement('div');
      newNode.style.border='1px solid black';  
      newNode.style.textDecoration = 'none';

now the above breaks if i use something like this

var newNode = document.createElement('div');
      newNode.style.border='1px solid black';  
      newNode.style.textDecoration = 'none !important';

using !important because globally a has underline and i want to remove underline from here

i am getting an error in second approach
1. What error?
2. Why set text-decoration on a div and not on the links in the div? Set the className and use a style sheet
if i declare the classname in my main global.css file, will it get it or i have to declare it just above where i am calling the function because i am making the function inside the JS File
If the class is declared in the CSS and the div is created after the CSS has loaded, the div will get the class.
ok i will try and get back to you
ok i tried like this

<!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>
<script>
function getMyValues(){        
	var show = window.showModalDialog("abc.cfm", window,"center=yes;dialogWidth:900px:dialogHeight:800px");         
		if(show!=undefined) {                 
			var aid = show.SID;                
			var arrID = aid.split(',');                
				for (var j=0; j<arrID.length; j++){                        
				var theDiv = 'projectsList'; // This is my parent Div name                        
				var newNode = document.createElement('div');  //I am trying to create a New Div inside the Div of the parent with the Styles, also want to pass asa hidden field with the each div which is being created inside the parent div   
				newNode.className = "classfile";                     
				newNode.innerHTML = arrID[j] + '<imgs src=img.png onclick=$(this).remove()>'; // I want that when i click on the image it should remove the whole DIV, currently it is removing only the Image icon, if i try this the code logic which is written                         
				theDiv.appendChild(newNode)                 
				}                        
		}
}
</script>
</head>

<body>
</body>
</html>

Open in new window

please guide
your onclick is only removing the image

onclick="var el = this.parent; el.parent.removeChild(el)"

would remove the div that contains it.
tried ur way!

got the error!

parent is null or not an object IN IE 7

in Mozilla i get this

el is undefined
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial