I was wondering how I might make a simple HTML that uses closure to make my variables non-global.
I have this code (that does not work) below. I hope it gets across what I am trying to do. I am new to JavaScript (one month now). Any suggestions?
[code]
<html>
<body>
<h1>Closure Test 1</h1>
<form name=”myform”>
<table border=”0″ cellspacing=”0″ cellpadding=”5″><tr>
<td><textarea name=”inputtext” rows=’23’ cols=’80’ onBlur=”addtext();”></textarea></td>
</tr></table>
</form>
<script type=”text/javascript”>
(function() {
function addtext() {
var newtext = document.myform.inputtext.value;
document.myform.outputtext.value = “”;
}
})();
</script>
</body>
</html>