Skip to main content

Posts

Showing posts from March, 2011

Dynamic control generation - Javascript code

The JS code for generating controls dynamically. Copy and paste the code and save it as an HTML file, take it on the browser to know the working of the script. The add Ctrl function will duplicate the TR of the table. On clicking the link "Add More Contact Persons" the new row of control will be created. On clicking the " Remove" link the corresponding row will be deleted.

JS function to convert string to US phone number format

Javascript function to change the string to US telephone number format Eg: if input string is 0115463234 ,it will be converted to (011)546-3234 function toPhoneFormat( obj ){ val=document.getElementById(obj).value; arrChars=val.split(''); formatedString=''; for(i=0;i < val.length;i++){ if(i==0) formatedString+='('; if(i==3) formatedString+=') '; if(i==6) formatedString+='-'; formatedString+=arrChars[i]; } document.getElementById(obj).value=formatedString; } Sample usage: Function is called in the onBlur event <input id="txtpersontel" type="text" name="persontel" maxlength="20" style="width:125px" onblur="toPhoneFormat('txtpersontel')" > Tweet

JS Function to check whether the string is numeric

Javascript function to check the string in the textbox is numeric function name : isNumber parameters : Input control object and flag to allow decimal points Function doesn't allow non numeric characters in the control the function can be called on onKeyUp event of the control. if permitDecimal = 0 then decimal point '.' is not allowed in string, else dot is allowed. function isNumber( obj ,permitDecimal ){ var val = document.getElementById(obj).value ; var te=val.match(/\d+\.?\d*/); document.getElementById(obj).value=te; val=te; if(val!=""){ if( isNaN(val) ){ endOFString=val.length-1; val=val.substring(0,endOFString); } if(!permitDecimal){ if(val){ val=val.toString(); document.getElementById(obj).value=val.replace(/\./g,''); } }else{ document.getElementById(obj).value=val; } } } Sample usage <input id="txtpersontel" type="text" name="persontel" maxlength="20" style=...


Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »
Member
Search This Blog