Posted on August 31, 2007 by Joey
In doing numerous technical interviews of Internet Application Developers, I’ve discovered that most of these candidates consider their JavaScript skills to be at an “expert” level or they feel their JavaScript skills are “very strong.” In the course of the interview, however, it is often discovered that the candidates only have a cursory understanding [...]
Filed under: Internet, JavaScript, Programming, Software, Technology, Web, Web 2.0 | 10 Comments »
Posted on August 17, 2007 by Joey
To add an option to a dropdown select box with JavaScript, first create the option that will be added. Then add the option, as shown in the following example.
If this is the select list:
<select name='dropdown' id='dropdown'>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
This JavaScript will add an option at the end of the list with a value of 3 and [...]
Filed under: JavaScript | 3 Comments »
Posted on August 15, 2007 by Joey
To remove an option from a dropdown select box with JavaScript, use the JavaScript remove method. Pass it the index of the option that should be removed. The index is 0-based, so to remove the first item in the select list pass 0, to remove the second pass 1 and so forth.
If this is the [...]
Filed under: JavaScript | Leave a Comment »
Posted on August 14, 2007 by Joey
A function can be created in JavaScript by using the function statement, as follows:
function CalculateTotal(intInput)
{
var intTotal = 0;
intTotal = intInput*2;
return intTotal;
}
To call this function in JavaScript code, simply do this:
CalculateTotal(4);
The curly braces are required as part of the function statement.
Filed under: JavaScript | 1 Comment »
Posted on August 12, 2007 by Joey
To remove all options from a dropdown select box with JavaScript, simply set the length property of the dropdown box to 0. For instance, if a dropdown select box is defined as follows:
<select name='Dropdown' id='Dropdown'>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
Use this JavaScript to remove all the options in the dropdown select box.
document.getElementById('Dropdown').length = 0;
Filed under: JavaScript | 6 Comments »
Posted on August 10, 2007 by Joey
To remove all the elements from a JavaScript array, simply set the array length to 0, as shown in the following example:
var aryTest = [1,2,3,4];
document.write(aryTest.length);
aryTest.length = 0;
document.write(aryTest.length);
Related articles:
JavaScript Arrays Summary and Reference
JavaScript Array length Property
Filed under: JavaScript | Leave a Comment »
Posted on August 10, 2007 by Joey
At work recently the need came up to determine the number of days in a month for a given month and year. This can be accomplished by creating a date object for the given month and year. Then do a while loop. In each iteration of the loop, set the day of [...]
Filed under: JavaScript | 1 Comment »
Posted on August 9, 2007 by Joey
Backslashes can be removed from a JavaScript string as follows:
var strBackslash = ‘\\backslash’;
var strReplace = strBackslash.replace(/\\/,”);
document.write(strReplace);
Related articles:
JavaScript Regular Expressions
Filed under: JavaScript, Programming, Regular Expressions, Software, Technology | Leave a Comment »
Posted on August 8, 2007 by Joey
To include an external JavaScript file in a file, use the script tag.
<script src='../filename.js'></script>
The src attribute refers to the path where the included file resides. The file specified is a file that contains JavaScript only and has no script tags.
Note that the end script tag immediately follows the beginning script tag.
Why use the script tag [...]
Filed under: JavaScript | Leave a Comment »
Posted on August 8, 2007 by Joey
To determine the operating system of the client machine on which a browser is executing JavaScript, use the appVersion property of the JavaScript navigator object, as demonstrated in the following example:
document.write(navigator.appVersion);
The information given in this property can be extrapolated, albeit in a somewhat rudimentary way, to determine whether the operating system is Windows or Macintosh, [...]
Filed under: JavaScript | Leave a Comment »