Javascript Cursor Position in TextBox

In 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 Object

To 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 ...

Javascript Date for VB developers

Dealing with date in web applications in client side is unavoidable, since there may be a lot of client side validations required based on date.
Why I have decided is, whenever a VB developer started working on web development. The JavaScript Object model is much different from VB and a good reference is required for equivalent methods, I have already discussed about string functions in separate article under JavaScript section.

DateAdd

I have used DateAdd function in Classic Vb, and liked it much. when i was looking for some equivalant i was unable to find it. 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

ItemType values
 Possible values can be passed as the item ty ...

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">

...

This is a test page

...

Read more here:   Inline Calendar or a DatePicker 

Function To Open a Popup window

JavaScript 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 ...

Read more here:   Javascript Open Pop Up window 

Function To Delete a Cookie

Cookie 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 ...

Read more here:   Javascript Delete Cookie 

Function to Read Cookie

Cookie 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 ...

Read more here:   Javascript Read Cookie 

Function to Set Cookie

Cookie 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 ...

Read more here:   Javascript Set Cookie 

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 LtrimRtrim(strInput))
}

Read more here:   Javascript Trim 

Function to trim a string

In 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 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 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 string

While 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 Function

To 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 String

While 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 property

we 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();

Read more here:   Javascript Len() string 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 Case

To use this Javascript Ucase function please use like t ...

Read more here:   Javascript Ucase 

Change Lower Case(LCase) Function

In 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();
}

...

Read more here:   Javascript Lcase 

What is OverFlow

The 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; ...

Read more here:   Remove Scroll bars with CSS 


Spam Bot Trap



   



Select Theme
White
Blue
Brown
Gray