I understand how to link an element that exists on the form with a prototype function or class.
But how do I link/bind a dynamically created element with the same prototype function or class
In this example the existing element "txt1" is linked when the page is loaded:
Now how can I do the same if "txt1" was created dynamically using .innerHTML like this:
Since txt1 does not exist when the page is loaded how can I bind "AutoSuggestCon trol" to this new element?
But how do I link/bind a dynamically created element with the same prototype function or class
In this example the existing element "txt1" is linked when the page is loaded:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="autosuggest.js"></script>
<script type="text/javascript">
window.onload = function () {
var oTextbox = new AutoSuggestControl(document.getElementById("txt1"), new RemoteStateSuggestions());
}
</script>
</head>
<body>
<p><input type="text" id="txt1" /></p>
</body>
</html>
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script type="text/javascript" src="autosuggest.js"></script>
<script type="text/javascript">
window.onload = function () {
var oTextbox = new AutoSuggestControl(document.getElementById("txt1"), new RemoteStateSuggestions());
}
</script>
<SCRIPT LANGUAGE="JavaScript">
<!--
function makeElement() {
var tr, td;
var tbody = document.getElementById("placeHolder");
tr = tbody.insertRow(tbody.rows.length);
td = tr.insertCell(tr.cells.length);
td.innerHTML = '<INPUT type="text" id="txt1" />';
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<input type="button" value="Make Element" onclick="makeElement();" />
<table>
<tbody id="placeHolder">
</tbody>
</table>
</BODY>
</HTML>
Comment