JavaScript is an Untyped Language

JavaScript is an untyped language. This means that a variable can hold any datatype. It also means that a variable may be assigned data of one particular datatype and then later be given data of a different datatype. For example:
var x = 'Joey JavaScript';
x = true;
x = 1;
In the preceding example, the variable x is [...]

JavaScript to Validate Positive Integer While Accepting Empty String

A few times at work recently we have had the need to validate a form input field as an integer while still accepting an empty sting as a valid value as well.
This can be done as follows:
var RE = /^\d*$/;
document.write(RE.test(2)); //true
document.write(RE.test('')); //true
document.write(RE.test('a')); //false
The regular expression in the preceding example specifies that the string being tested [...]

JavaScript XMLHttpRequest responseText Property

Once an XMLHttpRequest has been initiated, sent and a response received, the XMLHttpRequest will have a responseText property. This property contains the server response, excluding headers.
Note that responseText is not fully loaded until the XMLHttpRequest readyState is 4. The responseText property can also contain a partial portion of the final result text if readyState is [...]

JavaScript XMLHttpRequest responseXML Property

Once an XMLHttpRequest has been initiated, sent and a response received, the XMLHttpRequest will have a responseXML property, if an XML document is received from the server. This property contains the response received from the server that can be processed by JavaScript as XML. DOM methods can by applied through JavaScript on the XML. If [...]

JavaScript: How to Remove All Commas From a Number

The following can be used in JavaScript to remove all commas from a number:
var StartNumber = '444,555,666';
var ReplacedNumber = FormNumber.replace(/\,/g,'');
document.write(ReplacedNumber);
The preceding example uses the JavaScript replace function and utilizes a regular expression to replace all the commas in a number. In the regular expression, the backslash (\) before the comma is used as an [...]

JavaScript: How to Submit a Form When a Button is Clicked

Submitting a form can be accomplished with JavaScript by accessing the named form and then calling the submit method on it.
<form name="frmTest" action="somepage.html”" method="post">
First Name: <input type="text" name="FirstName">
<input type="button" onclick="document.frmTest.submit();" value="Submit Form">
</form>
The JavaScript occurs with the onclick attribute of the button input type. It uses the document object model to access the named form and [...]

JavaScript: How to Load a New Browser URL Page

There are a few different ways in which a new page can be loaded in a browser through JavaScript.
window.document.location.href = 'http://www.joeyjavascript.com';
window.document.location = 'http://www.joeyjavascript.com';
window.location = 'http://www.joeyjavascript.com';
location = 'http://www.joeyjavascript.com';
document.location.href = 'http://www.joeyjavascript.com';
document.location = 'http://www.joeyjavascript.com';
As seen in the previous examples, both the window object and the document object have a location property that can be assigned a URL. [...]

JavaScript: Accessing getElementById in Firefox

A common mistake when using the getElementById function in Firefox is failing to set the id attribute of the element being accessed. This will work in Internet Explorer because it treats the name attribute as the id attribute in the case where the id attribute is not provided. Firefox, however, is not forgiving on this [...]

JavaScript Conditional Operator (?:) Question Mark, Colon

JavaScript provides the conditional operator as a shortcut for an “if” statement. The conditional operator consists of a question mark (?) and a colon (:), as shown below:
var intTest = 1;
intTest == 1 ? x = 1 : x = 2;
document.write(x);
The expression preceding the question mark must evaluate to a Boolean value. If the [...]

JavaScript: How to Remove Comma from the End of a List

Occasionally in JavaScript a list will be built using a loop. On each iteration of the loop a comma will be added to separate the current list item from the list item that will be added on the next iteration of the loop. For the final item of the list, however, there is not another [...]