You can drop the onclick="showName();" and do this:
HTML Code:
<h2 id="notice"></h2>
<div id="displayName">
<h2>Display Name</h2>
<form name="nameForm" action="#">
<label>Name: </label><input type="text" name="name" />
<input type="submit" value="Display" />
</form>
</div>
<script>
var frm = document.nameForm;
frm.onsubmit = function() {
if( frm.name.value !== '' ) {
var displayName = document.getElementById('displayName'),
notice = document.getElementById('notice');
displayName.style.display = 'none';
notice.innerHTML = "Hello " + frm.name.value + ", and welcome to my site!"
}
return false;
};
</script>
See how there isn't any inline javascript now associated in the HTML?
Bookmarks