Posted on July 26, 2007 by Joey
The current month can be determined in JavaScript by using the getMonth method of the JavaScript date object, as follows:
var dteNow = new Date();
document.write(dteNow.getMonth());
The value returned by the getMonth method is an integer value between 0 and 11, with 0 being January and 11 being December. (Note that the date is determined from the [...]
Filed under: JavaScript, Programming | 3 Comments »
Posted on July 25, 2007 by Joey
The JavaScript string object contains an indexOf method. It returns the index in the string of the first occurrence of a specified character. The index is numbered starting at 0. For example:
var strTest = 'only one day';
document.write(strTest.indexOf('n'));
The index returned in the preceding example is 1, as 'n' is the second character in the string and [...]
Filed under: JavaScript, Programming | Leave a Comment »
Posted on July 24, 2007 by Joey
The current year can be retrieved in JavaScript by using the getFullYear method of the Date object, as follows:
var dteNow = new Date();
var intYear = dteNow.getFullYear();
document.write(intYear);
Filed under: JavaScript, Programming | 1 Comment »
Posted on July 22, 2007 by Joey
The day of the week can be retrieved in JavaScript by using the getDay method JavaScript’s Date object, as follows:
var dteNow = new Date();
var dteToday = dteNow.getDay();
document.write(dteToday);
The value returned by getDay is between 0 (Sunday) and 6 (Saturday). To convert this to a string representing the day of the week, use a switch statement.
var [...]
Filed under: JavaScript, Programming | Leave a Comment »
Posted on July 22, 2007 by Joey
A common problem with HTML input forms is that users tend to include dollars signs when inputting currency numbers. These dollars signs can be easily removed through JavaScript by using the JavaScript replace function and a simple regular expression. This is demonstrated in the following example:
var Amount = '$13.22';
var ReplacedAmount = Amount.replace(/\$/g,'');
document.write(ReplacedAmount);
This example shows [...]
Filed under: JavaScript, Programming, Regular Expressions, Software | Leave a Comment »
Posted on July 22, 2007 by Joey
The HTML label tag is used to label form elements as follows:
<label for="FirstNameLabel">First Name:</label>
<input type="text" name="FirstName" id="FirstNameLabel">
As seen in this example, the for attribute of the label tag binds it to the id attribute of the input control. Why use the label tag? Browsers handle the text in a label tag in a unique way. [...]
Filed under: Internet, JavaScript, Programming, Software | Leave a Comment »
Posted on July 20, 2007 by Joey
Three must-read JavaScript articles
101 Ways to Know Your Software Project is Doomed
My favorites:
You start considering a new job so you don’t have to maintain the application you are building
Developers use the excuse of ’self documenting code’ for no comments
You believe compiling is a form of testing
Your manager wastes 7 hours a week asking for progress [...]
Filed under: Internet, JavaScript, Programming, Software | Leave a Comment »
Posted on July 20, 2007 by Joey
The JavaScript isNaN function accepts one argument and returns true if that argument is not a number value and false if the argument is a number value. For example:
document.write(isNaN(10))//Is a number, returns false
document.write(isNaN('a'))//Is not a number, returns true
Filed under: JavaScript, Programming, Software | Leave a Comment »
Posted on July 17, 2007 by Joey
In JavaScript regular expressions, the caret (^) special character can be used in two ways.
First, it can be used as a line anchor, specifying the beginning of a line. I explained this previously in my post JavaScript Regular Expression Special Characters.
Second, it can be used inside a character class to negate the characters being [...]
Filed under: Internet, JavaScript, Programming, Regular Expressions, Software, Web | Leave a Comment »
Posted on July 16, 2007 by Joey
In a JavaScript regular expression the hyphen (also commonly referred to as the dash) can serve two purposes, depending upon where it is used in the expression.
First, a hyphen can be used as part of a regular expression if the hyphen needs to be found literally. An example of this is a regular expression that [...]
Filed under: Internet, JavaScript, Programming, Regular Expressions, Software, Web | Leave a Comment »