Inserting Form Elements using Javascript
Posted: Sat Oct 23, 2004 2:06 pm
For those who have Gmail, it'll be easy to understand. What I want to do is to have a button in which a user clicks to add extra textboxes just like you can do it in Gmail with attachments etc. I have analysed the Gmail code (yes, it's real complicated and came up with this...)
Code Found in Gmail:
Think that's about all you need... Gmail really likes to make it confusing so people like me can't copy... Cheers
Anyways, from the above code I have deduced the following:
And guess what! it doesn't work... In IE you get no error but in FireFox I get this,
Code Found in Gmail:
Code: Select all
function j(win,id){return win.document.getElementById(id)}
function W(win,id){return S(win).CM_formїid]}
function vg(win,Xh,II){var f=win.document.createElement(II);Xh.appendChild(f);return f}
function OH(win,id){var b=W(win,id);var Ku=b.attachmentcounter++;var af=j(win,"atts_"+id);var U=vg(win,af.childNodesї1],"div");var PF=aa?'style="position:absolute;visibility:hidden"':"";U.innerHTML="<span></span><input type=file size=50 "+PF+" name=file"+Ku+' onchange="top.js._CM_OnAttach(window,this)"'+"> "+"<span class=s "+(aa?'style="display:none"':"")+">"+V("remove","da_"+Ku,true)+"</span>";win.setTimeout(function(){var D=U.childNodesї1];if(aa){D.click()}else{D.focus()}}
,0);if(!aa){b.attachments++;Gg(win,id)}Mo(win,id);Vi(win,id,true)}Anyways, from the above code I have deduced the following:
Code: Select all
<html>
<head>
<title></title>
<script language="javascript" type="text/javascript">
<!--
var menuNum = 1;
function addMenu() {
var af = document.getElementById("atts_compose");
var f = document.createElement("div");
af.childNodesї1].appendChild(f);
f.innerHtml = '<input name="td2" type="text" class="td" size="25">';
}
//-->
</script>
</head>
<body>
<input name="td1link" type="button" class="td" value="OK" onclick="addMenu();">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td id="atts_compose"><div></div></td>
</tr>
</table>
</body>
</html>Any ideas what I could do to solve this?Error: uncaught exception: [Exception... "Node cannot be inserted at the specified point in the hierarchy" code: "3" nsresult: "0x80530003 (NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)" location: "file:///C:/******/test.htm Line: 14"]