Coast Line
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
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)
}
}
}
var theDiv = document.getElementById('p rojectsLis t'); // -- This is my parent Div ID
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
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
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);
}
}
}
ASKER
yes the way i am doing is bit different but same as above
i am using the following as:
var newNode = document.createElement('di v');
newNode.style.border='1px solid black';
newNode.style.textDecorati on = 'none';
now the above breaks if i use something like this
var newNode = document.createElement('di v');
newNode.style.border='1px solid black';
newNode.style.textDecorati on = 'none !important';
using !important because globally a has underline and i want to remove underline from here
i am using the following as:
var newNode = document.createElement('di
newNode.style.border='1px solid black';
newNode.style.textDecorati
now the above breaks if i use something like this
var newNode = document.createElement('di
newNode.style.border='1px solid black';
newNode.style.textDecorati
using !important because globally a has underline and i want to remove underline from here
ASKER
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
2. Why set text-decoration on a div and not on the links in the div? Set the className and use a style sheet
ASKER
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.
ASKER
ok i will try and get back to you
ASKER
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>
ASKER
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.
onclick="var el = this.parent; el.parent.removeChild(el)"
would remove the div that contains it.
ASKER
tried ur way!
got the error!
parent is null or not an object IN IE 7
in Mozilla i get this
el is undefined
got the error!
parent is null or not an object IN IE 7
in Mozilla i get this
el is undefined
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.