Usefull Scripts
Sunday, November 1, 2009
Form field limiter
Copy and paste this code where u want..
<br /> <!-- this script got from http://usefull-script.blogspot.com/Coded by: Ratnakar Mishra --><br /> <br /> <!--Step 1: Add the below script to the <HEAD> section of your page:--><br /> <script type="text/javascript" src="formfieldlimiter.js"> </script><br /> <!-- Step 2:for above references the following .js file and save into the same directory --><br /> var fieldlimiter={<br /> <br /> defaultoutput: "<b>[int]</b> characters remaining in your input limit.", //default message that gets output to statusid element<br /> <br /> uncheckedkeycodes: /(8)|(13)|(16)|(17)|(18)/, //keycodes that are not checked, even when limit has been reached. See http://www.javascriptkit.com/jsref/eventkeyboardmouse.shtml for avail keycodes<br /> <br /> limitinput:function(e, config){<br /> var e=window.event || e<br /> var thefield=config.thefield<br /> var keyunicode=e.charCode || e.keyCode<br /> if (!this.uncheckedkeycodes.test(keyunicode)){<br /> if (thefield.value.length>=config.maxlength){<br /> if (e.preventDefault)<br /> e.preventDefault()<br /> return false<br /> }<br /> }<br /> },<br /> <br /> showlimit:function(config){<br /> var thefield=config.thefield<br /> var statusids=config.statusids<br /> var charsleft=config.maxlength-thefield.value.length<br /> if (charsleft<0) //if user has exceeded input limit (possible if cut and paste text into field) thefield.value=thefield.value.substring(0, config.maxlength) //trim input for (var i=0; i<statusids.length; i++){ var statusdiv=document.getElementById(statusids[i]) if (statusdiv) //if status DIV defined statusdiv.innerHTML=this.defaultoutput.replace("[int]", Math.max(0, charsleft)) } config.onkeypress.call(thefield, config.maxlength, thefield.value.length) }, cleanup:function(config){ for (var prop in config){ config[prop]=null } }, addEvent:function(targetarr, functionref, tasktype){ if (targetarr.length>0){<br /> var target=targetarr.shift()<br /> if (target.addEventListener)<br /> target.addEventListener(tasktype, functionref, false)<br /> else if (target.attachEvent)<br /> target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)})<br /> this.addEvent(targetarr, functionref, tasktype)<br /> }<br /> },<br /> <br /> setup:function(config){<br /> if (config.thefield){ //if form field exists<br /> config.onkeypress=config.onkeypress || function(){}<br /> config.thefield.value=config.thefield.value<br /> this.showlimit(config)<br /> this.addEvent([window], function(e){fieldlimiter.showlimit(config)}, "load")<br /> this.addEvent([window], function(e){fieldlimiter.cleanup(config)}, "unload") <br /> this.addEvent([config.thefield], function(e){return fieldlimiter.limitinput(e, config)}, "keypress")<br /> this.addEvent([config.thefield], function(){fieldlimiter.showlimit(config)}, "keyup")<br /> }<br /> }<br /> <br /> }<br /> <br /> <!-- Step 3: Then, insert the below sample form onto your page, which contains two sample fields- a text and textarea field- with the script applied to them: --><br /> <form name="sampleform""><br /> <input type="text" name="george" style="width:250px" /><br /> <div id="george-status"></div><br /> <p><textarea name="ratnakar" id="ratnakar" cols="30" rows="5" style="width:250px">
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
Best script category
Alert Message
(2)
Background Effect
(5)
Buttons
(11)
Calculators
(6)
Forms
(3)
Fun Script
(1)
Java script
(3)
Miscellaneous
(2)
PHP Script
(10)
Search Box
(2)
Blog Archive
▼
2009
(57)
▼
November
(7)
Php code for Date of birth selction
Php code for web counter
Neon Text for your blogs or website
Daily Tips script for your website
Google search highlighter
Use of header ( ) in php
Form field limiter
►
October
(50)
Free Search Engine Submission
Followers
About Me
Ratnakar Mishra
View my complete profile
Number of visitors
No comments:
Post a Comment