PDA

View Full Version : How to create multiple instances using JS



webdeveloper
23 Oct 2009, 03:34 AM
Hi,

I have written a code below:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div id="emailRow" class="emailRowClass">
<div><input type="checkbox" class="checkbox1"></div>
<div><input type="text" class="textfield"></div>
<div><input type="checkbox" class="checkbox2"></div>
</div>

<div id="emailAddressList" class="emailAddressClass"></div>

<script type="text/javascript">
function emailRowContent(isSelected, emailAddress, severity)
{
this.isSelected = isSelected;
this.emailAddress = emailAddress;
this.severity = severity;
}

var emailAddressListObj = document.getElementById('emailAddressList');
var emailRowObj = document.getElementById('emailRow');
var arrayOfEmails = new Array(5);

for(i = 0; i < 5; i++)
{
arrayOfEmails[i] = new emailRowContent("checked", "fjkum@unknown.com", "");
emailAddressListObj.insertBefore(arrayOfEmails[i],arrayOfEmails[i-1]);
}
</script>
</body>
</html>

Basically, what I want to do is to dynamically create 5 instances of "emailRow" onto the web page making use of Javascript DOM. But have no success in getting it to work.

Can anyone shed some light?

Mike