Archive for the ‘Java Script’ Category

Transfer focus to button at run-time, if you have more than one buttons

Tuesday, December 15th, 2009
Code for ASP.Net in C#.Net:
TextBox1.Attributes.Add(“onkeydown”, “if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById(‘” + Button1.UniqueID + “‘).click();return false;}} else {return true}; “);

Fill HTML DropDown Using Javascript

Sunday, October 7th, 2007

function FillDropDown()
{
document.frm.dropdown1.innerHTML = “”;
var option1 = document.createElement(‘option’);
option1.appendChild(document.createTextNode(“— Please Select —”));
option1.setAttribute(‘value’, “”);
document.frm.ddType.appendChild(option1);
for(var x = 1; x <= 3; x++)
{
var option = document.createElement(‘option’);
option.appendChild(document.createTextNode(“cat-”+ x));
option.setAttribute(‘value’, x);
document.frm.dropdown1.appendChild(option);
}
}

JavaScript to Check Characters in a String

Friday, October 5th, 2007

//The function given below is use to validate the string in correct format or not. In case of correct format the function will return true as result otherwise will return false.

<script language=’javascript’ type=’text/javascript’>

function IsLettersDigitsChars(strString)
{
       var strValidChars = “?0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,()_&-. \n”;
       var strChar;
       var blnResult = true;
       if (strString.length == 0) return false;
       //  test strString consists of valid characters listed above
       for (i = 0; i < strString.length && blnResult == true; i++)
       {
             strChar = strString.charAt(i);
             if (strValidChars.indexOf(strChar) == -1)
             {
                      blnResult = false;
             }
       }
       return blnResult;
}

</script>

JavaScript: To Print the Data of Particular Area

Monday, October 1st, 2007

function CallPrint(DivId)
{
 var prtContent = document.getElementById(DivId);

 var WinPrint = window.open(”,”,’left=0,top=0,bottom=0,right=0,width=1003,height=800,toolbar=0,scrollbars=0,status=0′);
WinPrint.document.write(“<STYLE type=text/css media=print>.page {WRITING-MODE: tb-rl; HEIGHT: 80%}</style>”);
WinPrint.document.write(“<link href=StyleSheet.css rel=stylesheet type=text/css />”);

 WinPrint.document.write(prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();
 WinPrint.print();
 WinPrint.close();
 }
</script>