Javascript Cursor Position in TextBoxIn JavaScript getting the cursor position in textbox differs browsers to browsers. Firebox’s solution is simpler while internet explorer the solution is not straight forward and as well the result may not be accurate all the times. So the following is a simple approach to get the location of the cursor. It may not be accurate but simple and easy to understand. Internet Explorer and the Range ObjectTo get the caret location we need to work with selection to get it. To get the selection we can use document. Selection(Cursor Position in Textbox Javascript can be used with range).. Then a range from the selection can be taken by the selection object's createRange. This gives the range. Once the range is available the rest is simple calculations only. This script can be moved to a Javascript file for using in different places.
Sample Events are
OnMouseDown OnMouseUp OnKeyUp OnK ...
|
DateDiff function in Javascript
Like DateAdd function in Classic Vb DateDiff is a very useful function to find the date difference between two dates. Same as DateAdd there is no Javascript function available for DateDiff. So i started writing my own. As i always like vb styled functions to work on any module. I have actually tried to make it similar to vb Thanks Eric, who actually pointed some corrections in this article by his valuable comments. I have actually corrected them and the code is improved. However there was a small difference between DateDiff in Classic VB and DateDiff in VB.net. This article follows Vb.Net way as the following sample will give always Zero as DateDiff in Vb.Net. I ran the test for few hundred values both Javascript DateDiff and VB.Net DateDiff functions are inline.
StartDate 08/13/2009 23:55:00 EndDate 08/14/2009 00:05:00
result w ...
|
Float to align controls inlign 1Whenever DIVs are used in html markup, the DIVs are tend to flow vertically. Some times we may need to place them horizontally inline.
We can handle this using the float style. As follows
float: left; float: right; If Div1 and Div2 have to be placed inline then
<div id="Div1" style="float:left"> <div id="Div2" style="float:right">
...
|
Function To Open a Popup windowJavaScript function that opens a new window from the current window si called as Pop Up. The pop-up window is opened via the “open” method of the “window” object. The various parameters used are the URL of the window to open , the name of the window , and the features of the window. discussed little later. Note that these features can be in any order, so long as their syntax is correct.
To open a popup we need to call the window.open. This function has lot of parameters regarding the popup window . such as width, height, top, left etc.. Some of the possible functions i gave here.
status The status bar at the bottom of the window.
toolbar The standard browser toolbar,
location Address bar.
menubar As the name says
resize Allow/Disallow the user to resize the window
scrollbars Enable the ...
|
Function To Delete a CookieCookie is a small text file that's stored in cleint browser. It may contain data basically used for preferences configuration settings. Cookie is just a name-value collection of the data/configuration. There are few things that has to be configured like An expiry date after which it is no longer valid, The domain of the server it belongs to As soon as a request to a page is made, the cookie is added to the HTTP header. ASP.net can then read the data. Expiry date : Cookie can be set to expire on after some preied name-value: Each cookie has a name-value pair that contains the actual information. The name of the cookie can be used as a index. Domain :The domain tells the browser to which domain the cookie belogs to. JS does not have a function to delete a cookie. Inorder to delete a cookie, we need to create a cookie which expires in negative time frame. Then existing cookie w ...
|
Function to Read CookieCookie is a small text file stored in client browser. It may contain some data basically used for preferences and some configuration settings. Cookie is just a name-value collection of the data/configuration (normally in a plain text if you open in a editor). There are few things that can be configured like expiry date, the domain of the server from where it has been placed. As soon as a request to a page is made, the cookie is added to the Request or response. ASP.net can then read the data easily and make the changes to preferences in the server accordingly. Expiry date : Cookie can be set to expire on after some period name-value: Each cookie has a name-value pair that contains the actual information. The name of the cookie can be used as a index. Domain :The domain tells the browser to which domain the cookie belogs to. To read the cookie in the client browser using ...
|
Function to Set CookieCookie is a small text file that's stored in cleint browser. It may contain some data basically used for preferences configuration settings. Cookie is just a name-value collection of the data/configuration. There are few things that has to be configured like An expiry date after which it is no longer valid, The domain of the server it belongs to As soon as a request to a page is made, the cookie is added to the HTTP header. ASP.net can then read the data. Expiry date : Cookie can be set to expire on after some preied name-value: Each cookie has a name-value pair that contains the actual information. The name of the cookie can be used as a index. Domain :The domain tells the browser to which domain the cookie belogs to. Cookies can be managed by JavaScript using document.cookie. To set the cookie in the client browser using javascript. To delete a cookie, set it wi ...
|
Function to trim a string
While working with text often we need to trim the text. Basically a developer who has a very good knowledge in vb may look for the equivalent of Trim in javascript as in VB. Which is primarily used to trim the text. In JavaScript we dont have RTrim(), LTrim() , or Trim() or its euivalants. so we need to write our own function to deal with this. For trimming text in javascript there are a lot of possiblities here i am explaining some of them If you are placing this function in a common JavaScript file or anywhere in the same page’s script block. Then we can straight away call the Trim function as we do in VB. To trim the given string using string manipulation
function Trim(strInput) { return Ltrim( Rtrim(strInput)) }
|
Function to trim a stringIn most of the cases we may need to trim the white spaces . Basically a developer who has a very good knowledge in vb may look for the equivalent of RTrim . Which is primarily used to trim the Right hand side white spaces.
In JavaScript we have to use the string related function as the [variable]. [function name.]In this Case it is strInput.substring(); And we have to loop through all the charachters and if white space found then we have to strip it out.
If you are placing this function in a common JavaScript file or anywhere in the same page’s script block. Then we can straight away call the Rtrim function as we do in VB.
Read more here:
Javascript RTrim Trim Right
|
Function to trim(LTrim) a stringWhile working with text often we need to trim the text. Basically a developer who has a very good knowledge in vb may look for the equivalent of Trim in javascript as in VB. Which is primarily used to trim the text.
In JavaScript we dont have RTrim(), LTrim() , or Trim() or its euivalants. so we need to write our own function to deal with this. For trimming text in javascript there are a lot of possiblities here i am explaining some of them
If you are placing this function in a common JavaScript file or anywhere in the same page’s script block. Then we can straight away call the UCase function as we do in VB.
To trim the given string using string manipulation
Read more here:
Javascript LTrim Trim Left
|
MID Function to strip a stringWhile working with text often need to strip some text inside a text. Basically a developer who has a very good knowledge in vb may look for the equivalent of Mid() in VB. Which is primarily used to strip strings. In JavaScript we have to use the string related function as the [variable]. [function name.] In this Case it is strInput.substring(); If you are placing this function in a common JavaScript file or anywhere in the same page’s script block. Then we can straight away call the Mid function as we do in VB. How SubString works for Mid FunctionTo strip out the given string as per the given arguments wtith Substring Function
JavaScript Source Code
Read more here:
Javascript Mid strip string(substring)
|
Javascript Length StringWhile working with strings often we need to find a length of string, count of charachers etc. Basically a developer who has a very good knowledge in vb may look for the equivalent of len() in javascript as in VB. Which is primarily used for finding the length of string. In Javascript the length is a propertywe dont have any functions for finding lenth in String Object. But we have a property called Length in all string objects. and can be called as follows [variable]. [function name.] In this Case it is strInput.length();
|
Javascript Ucase Change Upper Case In most of the cases we may need to change the case to upper case. Basically a developer who has a very good knowledge in vb may look for the equivalent of UCase in VB. Which is primarily used for changing the string to Upper Case. In JavaScript we have to use the string related functions as the [variable]. [function name.]In this Case it is strInput.toUpperCase(); If you are placing this function in a common JavaScript file or anywhere in the same page’s script block. Then we can straight away call the Javascript Ucase function as we do in VB. function UCase(strInput) { return strInput.toUpperCase(); } How this function can be used to change to Upper CaseTo use this Javascript Ucase function please use like t ...
|
Change Lower Case(LCase) FunctionIn most of the cases we may need to change the case of text to lower case. Basically a developer who has a very good knowledge in VB may look for the equivalent of UCase in Js as in Visual Basic. Which is primarily used for changing the string to lower Case.
In JS we have to use the string related functions as [variable]. [function name.] In this Case it is strInput.toLowerCase();
If you are placing this function in a common JavaScript file or anywhere in the same page’s script block. Then we can straight away call the LCase function as we do in Classic VB. function LCase(strInput) { return strInput.toLowerCase(); } ...
|
What is OverFlowThe overflow indicates the browser to fit the content in a container as per the . Since the fit is based on the width and height, the property has to be used along with proper width and height. Otherwise it is going to be useless. There are few possible values for OverFlow, those are visible,hidden,auto,scroll
But for removing scroll bar use overflow: hidden; ...
|