Pages

Saturday, October 30, 2010

Maxlength for decimal field on textbox


set maxlegth=16 for 13 digit  + 1 .(point) +  2 fraction digit
MaxLength="16" onblur="fnDecMax(this.id,this.getAttribute('MaxLength'));"

javascript function
----------------------

function fnDecMax(id,maxLength)
{

theValue = document.getElementById(id).value;
maxLength = maxLength -1;
rx = /[^0-9.]/;
if(rx.test(theValue))
{
alert("The field can only contain numbers");
return;
}
if(theValue.indexOf(".") != -1)
{
theValue = theValue.substring(0,(theValue.indexOf(".") + 3));
}
lnt = theValue.length;
if(lnt > maxLength )
{
if(theValue.indexOf(".") == -1) {
theValue = theValue.substring(0,maxLength);
}
else
{
theValue = theValue.substring(0,(maxLength+1));
}
lnt = theValue.length;
}
if(lnt > (maxLength-2) && theValue.indexOf(".") == -1)
{
first = theValue.substring(0,(maxLength-2));
second = theValue.substring((maxLength-2));
theValue = first + "." + second;
}
document.getElementById(id).value= theValue;
}
Set Cursor Location from server side

Javascript function
function setCursorPositionToEnd(elementId)
{ var elementRef = document.getElementById(elementId);
var cursorPosition = document.getElementById(elementId).value.length;
if ( elementRef != null )
{
if ( elementRef.createTextRange )
{
var textRange = elementRef.createTextRange();
textRange.move('character', cursorPosition);
textRange.select();
}
else
{
if ( elementRef.selectionStart )
{
elementRef.focus();
elementRef.setSelectionRange(cursorPosition, cursorPosition);
}
else
{
elementRef.focus();
}
}
}
}

use This code at server side
string myScript = String.Format("setCursorPositionToEnd('txtSearch');"); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Myscript", myScript, true);
MaxLength for MultiLine textbox
onKeyUp="javascript:Count(this,5000);" onChange="javascript:Count(this,5000);"
function Count(text,long)
{
var maxlength = new Number(long); // Change number to your max length.
if(document.getElementById('txtDescription').value.length > maxlength)
{
text.value = text.value.substring(0,maxlength);
alert(" Only " + long + " chars");
}
}
Page Maximize Javascript
function maximize()
{ window.moveTo(0, 0); window.resizeTo(screen.width, screen.height-25); }

call this function on
body onload="maximize()"
Ajax Progrmming

Ajax(pronounced /'e?d?æks/) (shorthand for Asynchronous JavaScript and XML[1]) is a group of interrelated web development techniques used on the client-side to create interactive web applications. With Ajax, web applications can retrieve data from the server asynchronously in the background without interfering with the display and behavior of the existing page. The use of Ajax techniques has led to an increase in interactive or dynamic interfaces on web pages[citation needed]. Data is usually retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not actually required, nor do the requests need to be asynchronous.[2]
Like DHTML and LAMP, Ajax is not a technology in itself, but a group of technologies. Ajax uses a combination of HTML and CSS to mark up and style information. The DOM is accessed with JavaScript to dynamically display, and to allow the user to interact with, the information presented. JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads.

Monday, October 11, 2010

----get Querystring Value in Javascript-------------

var tablename = getQuerystring('tablename');
function getQuerystring(key, default_)
{
if (default_==null) default_="";
key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
var qs = regex.exec(window.location.href);
if(qs == null)
return default_;
else
return qs[1];
}

Search This Blog