Wednesday, June 11, 2008

Add and Remove HTML elements using javascript

Dear friends add "<" symbol in required places(i.e) in every tag....

script type="text/javascript" language="javascript">

var element_number = 1;
function addHTMLInput()
{
var d = document.createElement("div");
var l = document.createElement("a");
var textfield = document.createElement("input");
var s = document.createElement("div");
textfield.setAttribute("type", "text");
textfield.setAttribute("id", "textfield"+element_number);
textfield.setAttribute("name", "textfield"+element_number);
textfield.setAttribute("size", "50");
textfield.setAttribute("maxlength", "74");
l.setAttribute("href", "javascript:removeHTMLInput('s"+element_number+"');");
d.setAttribute("id", "s"+element_number);
s.setAttribute("style", " height:5px");
var image = document.createTextNode("Remove");
l.appendChild(image);

d.appendChild(s);
d.appendChild(textfield);
d.appendChild(l);
document.getElementById("moreHTML").appendChild(d);
element_number++;
textfield.focus();
}

function removeHTMLInput(i)
{
var elm = document.getElementById(i);
document.getElementById("moreHTML").removeChild(elm);
}
/script>

input type="text" name="element0" id="element0" size="50" maxlength="74">
div id="moreHTML">
/div >
div id="moreHTMLLink" style="display:block;" >
a href="javascript:addHTMLInput();">
Add Another Item
/a>
/div>

Labels: , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home