Feb
5th

How To Find Length of String In Javascript?

Files under Javascript | Leave a Comment

While working with strings, most probably we will need to find a length of string, count of charachers and etc. In JavaScript we can make use of the string related function as the [variable].length

So, here we go!! I decided to share some really basic source code. Here’s the example shows in an alert dialog box with the length of the string “My Name is David”

var mystring = “My Name is David”;
alert( mystring.length );

(more…)

Jan
23rd

Javascript Remove Blank Space In Text Field

Files under Javascript | Leave a Comment

This tutorial will help you to remove spaces in a text field using Javascript. Any spaces keyed in by the user will be removed when they click on the button or anywhere outside the text field.

javascript_remove_space

This string.split() is to find all the substrings in a string that are separated by one or more characters. Then, i used string.join() to join a sequence of strings.

My Sample of Codes:

You can try to copy and paste into a notepad and save it as .html to test and see the result.

(more…)

Jan
16th

Convert String to Lowercase In Javascript

Files under Javascript | Leave a Comment

Now you can learn how to convert to lower case letters by using toLowerCase() functions in JavaScript. So, in order to convert a string to lower case, then you need to call the toLowerCase() method on the string.

tolowercase

The toLowerCase() method will return a lower case string into a new text field called “output”.

Sample Code of Converting String to Lowercase

Place this code inside the head section.

<script>
function toLowercase() {
document.form.output.value = document.form.input.value.toLowerCase();

}
</script>

Place this code inside the body section.

(more…)

Oct
17th

Simple Drop Down Menu Tutorial

dropdownmenu

This week, you will learn how to create a simple drop down menu, which is a 1 level drop-down menu with timeout effect. In the other words, it is similar to treelike unordered list.

I just wrote the simple script for the menu that will be displayed on the page:

HTML Code

<ul id=”menuStyle”>
<li><a href=“#” onmouseover=”menuopen(’m1′)onmouseout=”closetime()”>Page 1</a>

<div id=“m1onmouseover=“cancelclosetime()” onmouseout=“closetime()”>
<a href=”#”>Subpage 1A</a>
<a href=“#”>Subpage 1B</a>
<a href=“#”>Subpage 1C</a>
<a href=“#”>Subpage 1D</a>
<a href=“#”>Subpage 1E</a>
</div>

</li>

<li><a href=“#” onmouseover=“menuopen(’m2′)” onmouseout=“closetime()”>Page 2</a>

<div id=“m2″ onmouseover=“cancelclosetime()” onmouseout=”closetime()“>
<a href=“#”>Subpage 2A</a>
<a href=”#”>Subpage 2B</a>
<a href=“#”>Subpage 2C</a>
<a href=“#”>Subpage 2D</a>
</div>

</li>

<li><a href=”#” onmouseover=“menuopen(’m3′)” onmouseout=“closetime()”>Page 3</a>

<div id=”m3″ onmouseover=“cancelclosetime()” onmouseout=“closetime()”>
<a href=“#”>Subpage 3A</a>
<a href=“#”>Subpage 3B</a>
</div>

</li>

<li><a href=“#” onmouseover=“menuopen(’m4′)” onmouseout=“closetime()”>Page 4</a>

<div id=“m4″ onmouseover=“cancelclosetime()” onmouseout=“closetime()”>
<a href=“#”>Subpage 4A</a>
<a href=“#”>Subpage 4B</a>
</div>

</li>

<li><a href=“#” onmouseover=“menuopen(’m5′)” onmouseout=”closetime()”>Page 5</a>

<div id=“m5″ onmouseover=“cancelclosetime()” onmouseout=“closetime()”>
<a href=“#”>Subpage 5A</a>
<a href=“#”>Subpage 5B</a>
<a href=“#”>Subpage 5C</a>
</div>

</li>

</ul>

As you can see, I’ve used unordered list for menu items. The event handlers that I used to control the show and hidden layer are onmouseover and onmouseout.

CSS Code

Refer to http://codebasic.net/dropdownmenu.css

See more…

(more…)

Sep
26th

Javascript Display Time of Last Visit

Files under Javascript | Leave a Comment

setcookie

setcookie

This tutorial is to teach you how to write a script to record the last visit of your visitor and displays it upon their return. If this is their first visit, then a welcome message is displayed. Otherwise the message with last time visit will be displayed.

You need to make use of cookie, which is stored on the visitor’s computer. Each time the same computer requests a page; it will send the cookie too.

In this example, I create a cookie with an expiration date of 1 day and checks to see if cookie is set, or it has been greater or equal to 1 day.

Create and Store a Cookie
Firstly, you need to create a function that stores the cookie name, the value of the cookie, and the number of days until the cookie expires in a variable.

(more…)