In the wikipedia entry Unobtrusive JavaScript there is an example of obtrusive JavaScript:
<input type="text" name="date" onchange="validateDate(this);" />
The solution is the following:
<input type="text" name="date" />
window.onload = function(){ //Wait for the page to load.
var inputs = document.getElementsByTagName('input');
for(var i=0,l=inputs.length;i<l;i++){
input = inputs[i];
if(input.name && input.name=='date'){
input.onchange = function(){
validateDate();
}
}
}
};
function validateDate(){
//Do something when the content of the 'input' element with the name 'date' is changed.
}
Is there a way to generate the first code sample from the second? In other words, is it possible to "render" the HTML of a page after JavaScript has acted on it?