Tuesday, April 7, 2009

Isnumeric function in JavaScript

Creating a JavaScrit Functon to check the Numeric Values in a field... Unfortunalltyl which is not there inJavaScript By Default...
the function goes like This

[code]
< SCRIPT language="JavaScript" >
<!--
function chkNumeric(strString)
// strString is the string passed to be checked

// check for valid numeric strings
{
// strvalidchars defines the set of characters which are valid in a numeric field
var strValidChars = "0123456789.-";
// strings
var strChar;
// boolresult is the variable which returns true is string is in correct format or false if it is not a valid numeric string
var boolResult = true;

if (strString.length == 0) return false;
// test strString consists of valid characters listed above
for (i = 0; i < strString.length && boolResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
boolResult = false;
}
}
return boolResult;
}

// -->
</SCRIPT>
[/code]

Now once a function is ready we can use it as follows to check a field and returns an error
message if the contents are not numeric:

[code]
if (document.formname.fieldname.value.length == 0)
{
alert("Please enter a value.");
}
else if (chkNumeric(document.formname.fieldname.value) == false)
{
alert("Please check - the string conatins non numeric value!");
}

[/code]





++

Thanks and Regards

Meetu Choudhary

(http://msdotnetmentor.com)

Wednesday, March 25, 2009

Silverlight 3- Beta - released

Silverlight 3- Beta - released

MicroSoft Released its Silverlight3 beta in MIX [conference for designers and developers at Las Vegas].

Its available for download at:

1. MicroSOft Silverlight 3 SDK Beta 1
2. MicroSoft Silverlight 3 Tools Beta 1 for Visual Studio 2008 SP1
3. The MicroSoft 3 beta Runtime

Tuesday, March 24, 2009

Creating Calender Using Java Script

Following is the JavaScript Code for the HTML File....the whole file is posted as an attachment please have a look on that for detailed Information...
Script in Head Tag
[code]
function showseldate(obj)
{
if(obj.value!="")
{
seldate.innerHTML="<b>" + parseInt(document.calform.drpmonth.value)+1 + "/" + obj.value + "/" + document.calform.drpyear.value + "</b>";
} }
function changecalendar()
{
var m,y;
m=document.calform.drpmonth.value;
y=document.calform.drpyear.value;
displaycalendar(m,y);
}
function showcurcal()
{
var dt=new Date();
var m,y; m=dt.getMonth(); y=dt.getFullYear();
displaycalendar(m,y);
}
function displaycalendar(m,y)
{
var nod=numofdays(parseInt(m)+1,y);
var wd; var dt=new Date();
var curday=dt.getDate(); dt.setDate(1);
dt.setMonth(m); dt.setFullYear(y); wd=dt.getDay();
clear();
for(var i=1;i<=nod;i++)
{
document.calform.txtday[wd].value=i;
if(i==curday)
{
document.calform.txtday[wd].style.backgroundColor="red";
document.calform.txtday[wd].style.color="white";
}
wd++;
}
}
function clear()
{
for(var i=0;i<42;i++)
{
document.calform.txtday[i].value="";
} }
[/code]
In Body[code]
for(var i=1;i<=6;i++)
{
document.write("tr bgcolor='#FFCC00' >");
for(var j=1;j<=7;j++)
{
document.write("td><div align='center'><input name='txtday' type='text' size='3' onclick='showseldate(this)' readonly></div></td>");
} document.write("</tr>"); }[/code]


--
Thanks and Regards
Meetu Choudhary

Monday, March 23, 2009

Blinking Text Using JavaScript

functions for the script tag in body
[code]
function prog1(objid)
{
var obj;
obj=window.document.getElementById(objid);
obj.style.backgroundColor="red";
obj.style.color="yellow";
}
function prog2(objid)
{
var obj;
obj=document.getElementById(objid);
obj.style.backgroundColor="yellow";
obj.style.color="red";
}
function blinktext()
{
if(p3.style.visibility=="visible")
{
p3.style.visibility="hidden";
}
else
{
p3.style.visibility="visible";
}
window.setTimeout("blinktext()",300);
}
[/code]
call binktext function onload of body tag and
in p tag use the following line
[code]
onmouseover="prog1('p1')" onmouseout="prog2('p1')"
[/code]

for more details please see the attachment
--
Thanks and Regards
Meetu Choudhary

Subscribe via email

Enter your email address:

Delivered by FeedBurner

MSDotnetMentor

MSDotnetMentor My Website http://msdotnetmentor.com