<scripttype="text/javascript">
/*
FormfieldLimiterscript-ByDynamicDrive
ForfullsourcecodeandmoreDHTMLscripts,visithttp://www.dynamicdrive.com
ThiscreditMUSTstayintactforuse
*/
varns6=document.getElementById&&!document.all
functionrestrictinput(maxlength,e,placeholder){
if(window.event&&event.srcElement.value.length>=maxlength)
returnfalse
elseif(e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
varpressedkey=/[a-zA-Z0-9\.\,\/]///detectalphanumerickeys
if(pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}
functioncountlimit(maxlength,e,placeholder){
vartheform=eval(placeholder)
varlengthleft=maxlength-theform.value.length
varplaceholderobj=document.all?document.all[placeholder]:document.getElementById(placeholder)
if(window.event||e.target&&e.target==eval(placeholder)){
if(lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}
functiondisplaylimit(thename,theid,thelimit){
vartheform=theid!=""?document.getElementById(theid):thename
varlimit_text='<b><spanid="'+theform.toString()+'">'+thelimit+'</span></b>charactersremainingonyourinputlimit'
if(document.all||ns6)
document.write(limit_text)
if(document.all){
eval(theform).οnkeypress=function(){returnrestrictinput(thelimit,event,theform)}
eval(theform).οnkeyup=function(){countlimit(thelimit,event,theform)}
}
elseif(ns6){
document.body.addEventListener('keypress',function(event){restrictinput(thelimit,event,theform)},true);
document.body.addEventListener('keyup',function(event){countlimit(thelimit,event,theform)},true);
}
}
</script>
<formname="sampleform">
<inputtype="text"name="george"size=20><br>
<script>
displaylimit("document.sampleform.george","",5)
</script>
<p>
<textareaname="john"id="johndoe"cols=25rows=15></textarea><br>
<script>
displaylimit("","johndoe",10)
</script>
</form>
http://www.corange.cn/archives/2008/01/125.html
/*
FormfieldLimiterscript-ByDynamicDrive
ForfullsourcecodeandmoreDHTMLscripts,visithttp://www.dynamicdrive.com
ThiscreditMUSTstayintactforuse
*/
varns6=document.getElementById&&!document.all
functionrestrictinput(maxlength,e,placeholder){
if(window.event&&event.srcElement.value.length>=maxlength)
returnfalse
elseif(e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
varpressedkey=/[a-zA-Z0-9\.\,\/]///detectalphanumerickeys
if(pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}
functioncountlimit(maxlength,e,placeholder){
vartheform=eval(placeholder)
varlengthleft=maxlength-theform.value.length
varplaceholderobj=document.all?document.all[placeholder]:document.getElementById(placeholder)
if(window.event||e.target&&e.target==eval(placeholder)){
if(lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}
functiondisplaylimit(thename,theid,thelimit){
vartheform=theid!=""?document.getElementById(theid):thename
varlimit_text='<b><spanid="'+theform.toString()+'">'+thelimit+'</span></b>charactersremainingonyourinputlimit'
if(document.all||ns6)
document.write(limit_text)
if(document.all){
eval(theform).οnkeypress=function(){returnrestrictinput(thelimit,event,theform)}
eval(theform).οnkeyup=function(){countlimit(thelimit,event,theform)}
}
elseif(ns6){
document.body.addEventListener('keypress',function(event){restrictinput(thelimit,event,theform)},true);
document.body.addEventListener('keyup',function(event){countlimit(thelimit,event,theform)},true);
}
}
</script>
<formname="sampleform">
<inputtype="text"name="george"size=20><br>
<script>
displaylimit("document.sampleform.george","",5)
</script>
<p>
<textareaname="john"id="johndoe"cols=25rows=15></textarea><br>
<script>
displaylimit("","johndoe",10)
</script>
</form>
http://www.corange.cn/archives/2008/01/125.html