Skip to main content

Improve your website's user interface using javascript

Hi friends,
This is after a very long time. I was so busy now the days.
Now i am sharing some client side javascript functions. Now the days most of the companies wants to give the as much as possible functionalite in the web applications like desktop applications. & one can achive this with the help of javascript. Another thing that comes into picture is AJAX. But now i will not talk about AJAX in this article. here i will describe some javascript techniques by which you can improve your web sites user interface & create it more user friendly. Lets start some basic tests:



String.prototype.IsBlank=function(){ var flag=true; for(var i=0;i<this.length;i++){var temp=this.substring(i,i+1); if(temp != " "){ flag=false; break; } } if(flag==true){return true;} else {return false;} };



Enter Your Name:
String.prototype.CheckBlank=function(fname){if(this.IsBlank()){alert(fname+genblnk);return true;}return false;};



Enter Your Name:




























Javascript Source Code for above functions:

/*
This Script contain prototypes to extend the features of builtin datatypes of javascript.
So that we can perform more advanced operations easily.
If you want to use these features in your code you must have to include this file in pages head section.
Author: Anuj Kumar Rathi
Email: rathi.del@gmail.com
*/
// define error messages
var allowed = "jpg.jpeg.JPG.JPEG";
var blnkmail="Email Can't be blank";
var mailfrmt="Enter a valid Email Address!";
var sharemailfrmt='Please make sure that email addresses contain no spaces and exactly one "@" sign!';
var confpwdblnk="Either Password or Confirm Password is blank!";
var pwdmismatch="Password doesn't match!";
var uidexists="Another User with this Email already registered!";
var uidsucessed="You can Proceed with this mail!";
var titleblnk="Title can't be blank!";
var genblnk=" can't be blank!";
var albumexists="Album already exists!";
var leastrecpt="Please enter at least one recipant!";
var msg_nan=" must be a Number";
var msg_naf=" must be a Float Number";

/* Add prototypes to builtin String datatype */

// Reverse a String
String.prototype.reverse=function(){ var out='';for(var i=this.length-1;i>=0;i--){ out+=this.substr(i,1);} return out;};

// Check if string is Blank or Not
String.prototype.IsBlank=function(){ var flag=true; for(var i=0;i<this.length;i++){ var temp=this.substring(i,i+1); if(temp != " "){flag=false; break;}}if(flag==true){return true;}else {return false;}};

// Check if string is Blank or Not. If blank then alert an Error Message with specified keyword
String.prototype.CheckBlank=function(fname){if(this.IsBlank()){alert(fname+genblnk);return true;}return false;};

// Check if string is represantinf a number or Not.If not a number then alert an Error Message with specified keyword
String.prototype.isNumber=function(fname){if(isNaN(parseInt(this))){alert(fname+msg_nan);return false;}return true;};
String.prototype.isFloat=function(fname){if(isNaN(parseFloat(this))){alert(fname+msg_naf);return false;}return true;};
String.prototype.isNumberInteger=function(){return (!isNaN(parseInt(this))) ? true : false;};
String.prototype.isNumberFloat=function(){return (!isNaN(parseFloat(this))) ? true : false;};
String.prototype.removeLeadingSpaces=function (){var removeChar=' ';var returnString=this; if(removeChar.length){while(''+returnString.charAt(0)==removeChar){returnString=returnString.substring(1,returnString.length);}}return returnString;}
String.prototype.removeTrailingSpaces=function (){var removeChar=' ';var returnString=this;if(removeChar.length){while(''+returnString.charAt(returnString.length-1)==removeChar){returnString=returnString.substring(0,returnString.length-1);}}return returnString;}
String.prototype.removeLeadingAndTrailingSpaces=function (){var removeChar=' ';var returnString=this;if(removeChar.length){while(''+returnString.charAt(0)==removeChar){returnString=returnString.substring(1,returnString.length);}while(''+returnString.charAt(returnString.length-1)==removeChar){returnString=returnString.substring(0,returnString.length-1);}}return returnString;}

// Check if string is valid email or not
String.prototype.isValidEmail= function (){
var at="@"; var dot="."; var lat=this.indexOf(at); var lstr=this.length; var ldot=this.indexOf(dot);
if (this.indexOf(at)==-1){return false;}
if (this.indexOf(at)==-1 this.indexOf(at)==0 this.indexOf(at)==lstr){return false;}
if (this.indexOf(dot)==-1 this.indexOf(dot)==0 this.indexOf(dot)==lstr){return false;}
if (this.indexOf(at,(lat+1))!=-1){return false;}
if (this.substring(lat-1,lat)==dot this.substring(lat+1,lat+2)==dot){return false;}
if (this.indexOf(dot,(lat+2))==-1){return false;}
if(this.substring(this.lastIndexOf(dot)+1).length>=0){return false;} if (this.indexOf(" ")!=-1){return false;}return true;}

//check multiple mails separated with 'sepval' against valid email String.prototype.checkIsValidEMails=function(sepval){ if(this.IsBlank()){alert(leastrecpt);return false;} var valToCheck = this.split(sepval); var flag=true;var part_num=0; while (part_num < valToCheck.length){ if(valToCheck[part_num].IsBlank()==false && valToCheck[part_num].isValidEmail()==false){ flag = false;alert(sharemailfrmt); alert('Check the following email id to correct \n\n' + '\t' +valToCheck[part_num]); break;}part_num+=1;}return flag;}

// Make a string to Title case eg. Anuj Kumar Rathi
String.prototype.makeTitleCase=function (){var tmpStr,tmpChar,preString,postString,strlen;tmpStr=this.toLowerCase(); stringLen=tmpStr.length; if (stringLen>0){for (i=0;i0){tmpChar=tmpStr.substring(0,1).toUpperCase();postString=tmpStr.substring(1,stringLen);tmpStr=tmpChar+postString;}return tmpStr;}

// Count the number of words ia a string. Words should be seperated by a single space (' '). If more then spaces found then it will be treated as multiple word
String.prototype.countWords=function (){return this.split(' ').length;}

Comments

Popular posts from this blog

How to Prevent Users to Press F5 key (Refresh button)

Some times we want to prevent user to Press F5 key to prevent Page Refresh. You can use the below script. Paste this code in the Head Section of your Page. <script language=javascript> document.onkeydown = function(){ if(window.event && window.event .keyCode == 116){ window.event.keyCode = 505; // Capture and remap F5 } if(window.event && window.event .keyCode == 505){ // New action for F5 return false; // Must return false }} </script>

Access Different interface method with same Name implemented in a class

We use interface and multiple interface inherit it into class, then we implement the methods of interface as it is necessary but what will happen if two interface have the same mentods with same signature and inherited in the same class? Now questions arises from here are : Q1) Both the methods will be implementable which is with the same name and signature? Q2) If methods are implementable then how it is possible? Q3) If it is possible then can we access both the methods? Q3) If it is possible then what is the way to access these methods publically? The answer of all the above question is below: 1) Yes both the methods with same name and signature is implementable. 2) we have to implement interface explicitely preceding with iterface name. 3) Yes it is possible to access the methods. 4) Yes we can

Should have on tips of our lips.........ACID PROPERTIES

Introduction    When ever we process any DML statements transactions are implicitly called. Ie. when ever no begin  transaction statement insert ,delete, update statements will have transaction statements around them implicitly. ACID concept is one of the oldest and important properties of the Database. It sets forward four goals that every database management system must strive to achieve: atomicity, consistency, isolation and durability. No database that fails to meet any of these four goals can be considered reliable. Atomicity Atomicity states that database modifications must follow an "all or nothing" rule. Each transaction is said to be "atomic." If one part of the transaction fails, the entire transaction fails. It is critical that the database management system maintain the atomic nature of transactions in spite of any DBMS, operating system or hardware failure. Consistency Consistency states that only valid data will be written to the database. If,...