Tuesday, March 4, 2008

Dynamic Html

Dynamic HTML, or DHTML, is a collection of technologies used together to create interactive and animated web sites.
Dynamic Html use Html,javascript,css,Document Object Model.
Nowadays dynamic html heavily used in dynamic website.
To create a dynamic html first you have to create a body object

var body = document.getElementsByTagName("body")[0];=>get the reference for the body
If a document need to keep more than one dynamic html at that moment we just keep a table tag and inside of it take a tbody tag with a specific id.
In the form we can do this..

Now we will use the above tbody object to append the child.
In case of mozila we use createElementNS() and for other createElement()
createElementNS() method creates an element node with a namespace.
Where ns =A string that specifies the namespace name for the element node
name =A string that specifies the name for the element node

Here we have to remember one thing:- thead,tbody,tfoot all are append with table.
Where thead is used for table header
tbody is used for table body
tfoot is used for table footer

One Example has been given bellow how to create dynamic html?
var tbl = document.createElement("table"); =>creates a table element.
var tblBody = document.createElement("tbody");=>creates a tbody element.
var row = document.createElement("tr");=>creates a table row.
var cell = document.createElement("td");=>Create a element cell that mean table column.
var cellText = document.createTextNode("Text");=>Create a node and make the text.
Now we will append element with its parrent.
cell.appendChild(cellText);=>Append text to the td
row.appendChild(cell);=>Append td to the row.
tblBody.appendChild(row);=>Append row to the table body.
tbl.appendChild(tblBody);=>Append table body to the table.
body.appendChild(tbl);=>Append table to the body.
tbl.setAttribute("border", "2");=>sets the border attribute of tbl to 2.

We can dynamically also create html control like the following way.

Create TextBox Control
objTextBoxNode = document.createElement("input");
objTextBoxNode.id = "txtName";
objTextBoxNode.value = "Priyabrata";

In the above syntax a TextBox element will be created with the id ="txtName" and value =Priyabrata.

Create CheckBox Control.
objCheckBoxNode = document.createElement("input");
objCheckBoxNode.id = "chkName";
objCheckBoxNode.value = "Yes";
objCheckBoxNode.checked = true;

In the above syntax a CheckBox element will be created with the id ="chkName" and value =Yes.It is by default checked.

Create Button Control.
objButtonNode = document.createElement("input");
objButtonNode.id = "btnName";
objButtonNode.value = "Add";
objButtonNode.onclick = function addFunction(){} Here we can write down the add syntax

In the above syntax a Button element will be created with the id ="btnName" and value ="Add".Here also attach a onclick event which call a function addFunction().

To Remove a element from the dynamic component we have to reach their top most parent and remove the required html component.

Note:At the time of remove a dynamic component we have to rememebr that if we want to remove that dynamic component then instead of declare the component as object we have to declare it as var otherwise we will get an exception and no component will be deleted.

For example
objDivElement = documents.getElementsByTagName("div");
here we create div object.
To get how many div element of a document we can use.
objLength = objDivElement.length;

How to create a clone node of an object

Suppose we want to create a clone node of objDivElement then...
objCloneNode = document.cloneNode(objDivElement);
objCloneNode.style.position = 'absolute';
objCloneNode.style.top = parseInt(startY) + 'px';
objCloneNode.style.left = parseInt(startX) + 'px';
document.onmousemove = Drag;
document.onmouseup = Drop;

Sunday, March 2, 2008


How to call Client side code from server side

How to show message If client is disabled a specified time

How to get input element value which stay inside a td
Say the html is like following ..
1>first create the table object
objTable = document.getElementById("TABLEID");
objTR = objTable.getElementsByTagName("tr")[0];
objTD = objTR.getElementsByTagName("td")[0];
objInput = objTD.getElementsByTagName("INPUT")[0];
How to get parent node from a click event
click event fire here In the above structure we will find a parent element from a click event.
Javascript Object
1.ArraYObj = {}; =>In javascript this way we can define an array obj
2.ArrayObj = new Array();
obj = function(){}=>This way we can define a function and here the function behave as object
Note:1.An element's offsetLeft and offsetTop properties return the pixel distance the element is offset from its offsetParent.The main offsetParent is body but
In the above ex referenc to the image id offset parent is <td>

After creating a event object in the following way we can call a function at the time of fire an event.

eventobj = document.getElementById('testeventid');
eventobj["onclick"] = function() { alert("ok");};
eventobj["onmouseover"] = function() { alert("bk");};

Singletone javascript function

In Javascript we can alocate a value into a member of an object and simultaneously call a function like the following way
testFunction().value2 = "test";