Not exactly an event but it has the same general purpose. Basicly it will fire the event when the user stops typing for 500 miliseconds. The reason for this, is I have an ajax form and I want the form to validate automaticly (without having to wait for the onchange event to fire). I was wondering first of all if this is a good way to do it? (simplicity please!) and secondly how can I improve this (efficiency wise) or is it fine as is:
Example:
JS:
HTML:
[HTML]
<html>
<head>
<script type="text/javascript" src="onpause.js "></script>
<script type="text/javascript">
<!--
function checkit(){
if(document.get ElementById('me ').value.length > 6){
document.getEle mentById('submi tbutton').disab led = false;
} else {
document.getEle mentById('submi tbutton').disab led = true;
}
}
function checking(){
document.getEle mentById('submi tbutton').disab led = true;
}
-->
</script>
</head>
<body onload="onPause (document.getEl ementById('me') , checkit, checking);">
<input type="text" id="me" />
<input type="submit" id="submitbutto n" value="Submit!" disabled="disab led">
</body>
</html>
[/HTML]
Thanks in advance, Josh
Edit: Gah, just realised the offPause function will not work, any ideas?
Example:
JS:
Code:
function onPause(theobj, qfunction, qverifyifunction){
if(qfunction && theobj){
var onp_currenttimer = false;
var thefunction = function(){
if(qverifyifunction)qverifyifunction();
if(onp_currenttimer)clearTimeout(onp_currenttimer);
onp_currenttimer = setTimeout(qfunction, 500);
}
if (theobj.attachEvent)
theobj.attachEvent('onkeyup',thefunction)
else if(theobj.addEventListener)
theobj.addEventListener('keyup',thefunction,false)
else
alert('Browser is out of date, please update.');
} else alert("function and object arguments required for onPause function.");
}
function offPause(theobj, thefunction){
if (theobj.detachEvent)
theobj.detachEvent('onkeyup',thefunction)
else if(theobj.removeEventListener)
theobj.removeEventListener('keyup',thefunction,false)
else
alert('Browser is out of date, please update.');
}
[HTML]
<html>
<head>
<script type="text/javascript" src="onpause.js "></script>
<script type="text/javascript">
<!--
function checkit(){
if(document.get ElementById('me ').value.length > 6){
document.getEle mentById('submi tbutton').disab led = false;
} else {
document.getEle mentById('submi tbutton').disab led = true;
}
}
function checking(){
document.getEle mentById('submi tbutton').disab led = true;
}
-->
</script>
</head>
<body onload="onPause (document.getEl ementById('me') , checkit, checking);">
<input type="text" id="me" />
<input type="submit" id="submitbutto n" value="Submit!" disabled="disab led">
</body>
</html>
[/HTML]
Thanks in advance, Josh
Edit: Gah, just realised the offPause function will not work, any ideas?
Comment