Thursday, November 20, 2008

Javascript: Making Initial Letter Capital for text box

Following script will work to make the initial letter in your text box automatically.

I have placed this in onKeyup event, you can use it according to your own requirements.

onkeyup=
"this.value=this.value.substring(0,1).toUpperCase()
+this.value.substring(1,this.value.length)"


Here is the example:

Thursday, November 13, 2008

JavaScript: Function To Check Whether provided string contains some wildcard character

The following function returns true if the string value contains the specific wild-card character.

Parameters:

1- fieldValue -- String

It is a string that needs to be checked whether it contains some special/wildcard characters

2- wildChar -- String/ Single Char

It is a character that you want to search whether it is present in the string passed as first parameter of this function.


function containsWildCard(fieldValue, wildChar)
{
// var fieldValue = window.document.getElementById("fieldID").value;
if (fieldValue.split(wildChar).length > 1)
{
alert ("WildCard!");
return false;
}
else
{
alert ("No - WildCard!");
return true;
}

}

Monday, November 3, 2008

Javascript: Function To Get Currrent Time

function getCurrentTime()
{
var d = new Date();

var hour=d.getHours();
var minute=d.getMinutes();
var second=d.getSeconds();

if(hour<10)
{
hour = '0'+hour;
}
if(minute<10)
{
minute= '0'+minute;
}

if(second<10)
{
second= '0'+second;
}

var time =hour+':'+minute+':'+second

return time;
}