C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Javascript »

Common used Javascript functionality.


Posted Date: 14 Aug 2009    Resource Type: Code Snippets    Category: Javascript
Author: Jyoti SharmaMember Level: Gold    
Rating: 1 out of 5Points: 15



Common used Javascript functionality



1. Show a popup if textbox is blank.

function CheckForEmptyTextbox()
{
var s;
var txtValue;
txtValue = document.getElementById('TextBox1');
if (txtValue.value == '')
{
s = confirm('TextBox1 is blank, do you want to continue?');
return s;
}
return true;

}

protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "javascript: CheckForEmptyTextbox();");
}


2. show an alert if user entered a non numeric value in the textbox.

function checkForNumeric(txtVal)
{
var len = txtVal.value.length;
var charVal = 0;
for (var i=0;i {
charVal = txtVal.value.charCodeAt(i);
if (!((charVal >= 48 && charVal <= 57)))
{
alert("Only Numeric Values are Allowed");
txtVal.value = '';
txtVal.focus();
return false;
}
}
return true;
}
input type="text" id="txtNumber" onchange='checkForNumeric(this)'


3.Allow user to enter only numeric value.

function AllowNumericValue(myevent)
{
var charVal = (myevent.which) ? myevent.which : myevent.keyCode
if (charVal > 31 && (charVal < 48 || charVal > 57))
{
return false;
}
return true;
}
input type="text" id="Text2" onkeypress="return AllowNumericCharacters(event)"


4. Allow user to enter only character value.

function AllowCharacterOnly(myevent)
{
var Val = (myevent.which) ? myevent.which : myevent.keyCode
if ((Val > 64 && Val < 91) || (Val > 96 && Val < 123))
{
return true;
}
return false;
}
input type="text" id="txtString" onkeypress="return AllowCharacterOnly(event)"


5. On lost focus of textbox get the product of two textboxes.

function Multiplication()
{
var first = document.getElementById('input1');
var second = document.getElementById('input2');
var third;

third.value = first.value * second.value;
}
input type= "text" id="txtvalue2" onblur='Multiplication()'



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Javascript  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Preventing Multiple Button Click using Javascript
Previous Resource: Validation to Check for special Character
Return to Discussion Resource Index
Post New Resource
Category: Javascript


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use