Table of contents
Open Table of contents
Article body
- JavaScript’s split() divides a string according to the specified rule; the default separator described here is a comma. To split a number, first convert it to a string. For example:
var a = 1000;
document.write(a.split(”));
The code above produces an error.
You need to convert the value with tostring() before using it.
- JavaScript’s replace() replaces content according to a specified rule. It can be used to format numbers with thousands separators. The steps are:
Define the matching regular expression: var reg = /\d{1,3}(?=\d{3})+$)/g;
Insert commas into the number: a.toString().replace(reg,”$&,”);
This formats the number with thousands separators.
- To set focus on a particular input, use:
$(“input [name = taxcode]“).focus();