|
Posted by Jonathan N. Little on 06/25/06 04:50
Event handlers attached by 'addEventListener' do not seem to pass values
in time to cancel form submission unlike the methods that it is supposed
to replace. In an attempt to keep the markup as clean as possible, I add
the handlers from the attached javascript page and I have noticed the
trouble. Small demo to illustrate:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Attached Events</title>
<script type="text/javascript">
function cancelIt(){
alert("This should cancel the form submission");
return false;
}
function init(){
var e = document.getElementById('findme');
if(e.addEventListener){
e.addEventListener('click', cancelIt, false);
}
else if(_s.attachEvent){ //MS IE support
a.attachEvent("onclick", cancelIt);
}
e = document.getElementById('me2');
e.onclick=cancelIt;
}
//attach event after page loads
if(window.addEventListener){
window.addEventListener('load',init,false);
}
else if(window.attachEvent){
window.attachEvent("onload", init);
}
</script>
</head>
<body>
<script type="text/javascript">
alert("Do your have a query string" + location.search);
</script>
<form method="get">
<div>
<input type="hidden" name="test" value="posted">
Hard coded the old way not desirable, JS in markup<br>
<input type="submit" value="Hard Coded" onclick="return cancelIt()">
<hr>
Attached by addEventListener does pass the FALSE in time
<br><input type="submit" value="By Listener" id="findme">
<hr>
Ok, effect, not hard coded, but does not append but replace handlers
<br><input type="submit" value="Direct Dot Coded" id="me2">
</div>
</form>
</body>
</html>
--
Take care,
Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Navigation:
[Reply to this message]
|