Internet is growing Every Seconds :: Industry is growing Every Year

Wednesday, March 17, 2004

client side validation 2

Javascript validation

validNum(formField,fieldLabel,required)
validRequired(formField,fieldLabel)
Trim(str)
LTrim(str)
RTrim(str)
function IsEmpty(ctrl,mess)




function validNum(formField,fieldLabel,required)
{
var result = true;

if (required && !validRequired(formField,fieldLabel))
result = false;

if (result)
{
if (!allDigits(formField.value))
{
alert('Please enter a number for the "' + fieldLabel
+'" field.');
formField.focus();
result = false;
}
}

return result;
}


function validRequired(formField,fieldLabel)
{
var result = true;

if (formField.value == "")
{
alert('Please enter a value for the "' + fieldLabel +'"
field.');
formField.value=Trim(formField.value);
//alert('d');
formField.focus();
result = false;
return result;
}

if (IsEmpty(formField,"Please enter a value for "+fieldLabel))
{
formField.value=Trim(formField.value);
result = false;
}

return result;


}


function Trim(str)
/*
PURPOSE: Remove trailing and leading blanks from our string.
*/
{
return RTrim(LTrim(str));
}

function LTrim(str)
{
var whitespace = new String(" \t\n\r");

var s = new String(str);

if (whitespace.indexOf(s.charAt(0)) != -1) {
var j=0, i = s.length;

while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
j++;
s = s.substring(j, i);
}
return s;
}
function RTrim(str)
{
var whitespace = new String(" \t\n\r");
var s = new String(str);

if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
var i = s.length - 1; // Get length of string
while (i > = 0 && whitespace.indexOf(s.charAt(i)) != -1)
i--;
s = s.substring(0, i+1);
}

return s;
}



function IsEmpty(ctrl,mess)
{
var name=ctrl.value;
for(i=0;i < name.length;i++)
{
if (name.charAt(i) !=" ")
return false;
}

alert(mess);
ctrl.focus();
return true;
}

Wednesday, March 03, 2004

Asp Function 13

Asp Function 13

Tuesday, March 02, 2004

Asp Function 12

Asp Function 12

Monday, March 01, 2004

ASP Function : nb_getMaxID

This Function is used to get the maximum id existing in the table.
It accepts 2 arguments, namely tbl_name and fld_name
TableName – Name of the Table.
FieldName – Name of the Id Field(Colum name)
It returns the Maximum Id as Integer.

ASP code

Set Con = Server.CreateObject("ADODB.Connection")
CON.ConnectionString ="Provider=SQLOLEDB.1;User
Id="NB_USERiD";password="NB_PASSWORD";Persist Security
Info=False;Initial Catalog=db_name;Data Source="sYSTEM NAME";"
Con.open
Public Function nb_getMaxID(TableName,FieldName)
set nb_rsmax = Server.CreateObject("ADODB.RecordSet")
sql = "select max("&FieldName&") as Cnt from "& TableName '& " where
"& WhereCLs
nb_rsmax.open sql,Con
if not nb_rsmax.eof then
MaxCnt = nb_rsmax("Cnt")
else
MaxCnt=0
end if
if trim(MaxCnt)="" or isEmpty(MaxCnt) or Isnull(MaxCnt)then maxCnt=0
nb_rsmax.close
set nb_rsmax=Nothing
nb_getMaxID=MaxCnt
End Function

Payroll_ID=nb_getMaxID("Tbl_Payroll_Head", "Payroll_ID")+1 ' This is employee id