How can the ‘Enter’ key be disabled?
In order to avoid the Form Submission by pressing the ’Enter Key’ you have to write following code on the KeyPress Event Of the Body Tag function DisableEnterKey() { if (window.event.keyCode == 13) { event.returnValue=false; event.cancel = true; } } <body onkeydown=”DisableEnterKey();”>
Is there Trim function available in Javascript?
There is no predefined trim function available. The function written below is used to Trim white spaces. //Trim Function 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; while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i–; s = s.substring(0, i+1); } return s; } function Trim(str) { return RTrim(LTrim(str)); }
How can we check whether the cookie is enabled?
It can be done by checking the read only property navigator.cookieEnabled. navigator.cookieEnabled will give the value true/false based on the browser support for cookies. functionCookieEnabled() { if(navigator.cookieEnabled) { alert(‘Cookie Enabled’); } }
How to truncate the data in the column
VB.NET Protected function TruncateData( Byval strNotes as string) If strNotes.Length > 20 then Return strNotes.Substring(0,20) + ‘…’ Else return strnotes End function C# protected string TruncateData( string strNotes ) { if (strNotes.Length > 20) { return strNotes.Substring(0,20) + ‘…’; } else { return strNotes; } }
How the browser name can be detected?
We can use navigator.appName property, to identify the browser we are using .For Netscape browsers, the value of navigator.appName is ‘Netscape’. For Microsoft Internet Explorer browsers,the value of navigator.appName is ‘Microsoft Internet Explorer’ . The following code is used for browser detection. function BrowserDetect() { document.write(’navigator.appName = ’+navigator.appName+’ ’) document.write(’navigator.userAgent = ’+navigator.userAgent+’ ’) if ((navigator.userAgent).indexOf(‘Opera’)!=-1) { document.write(‘You are using an Opera browser.’) } else if (navigator.appName==’Netscape’) { document.write(‘You are using a Netscape browser.’) } else if ((navigator.appName).indexOf(‘Microsoft’)!=-1) { document.write(‘You are using Microsoft Internet Explorer.’) } }