Using with the jQuery Globalization Plugin in ASP.NET | 2 | WebReference

Using with the jQuery Globalization Plugin in ASP.NET | 2


[prev]

Working with the jQuery Globalization Plug-in

To work with the jQuery Globalization Plugin, you should include the necessary scripts as shown below.

<script src="Scripts/jquery-1.4.2.js" type="text/javascript"></script>
<script src="Scripts/jquery.glob.js" type="text/javascript"></script>
 <script src="Scripts/globinfo/jQuery.glob.min.js" type="text/javascript"></script>

The jQuery.glob.all.js script file contains the necessary globalization information for all the supported cultures (more than 350 cultures are supported). Moreover, the jQuery Globalization plugin extends the jQuery library with a set of new methods that you can use to set culture information. Such methods include: format(), preferCulture(), etc.

The $.format() method is used to format numbers, dates and currency values. This method accepts two parameters - the value to be formatted and the format specifier. If you have the necessary scripts in place, you can use the jQuery Globalization plugin to format data as shown in the code snippet below:

$.preferCulture("en-US");
var amountValue = $.format(9060.32, "c");
var dateValue = $.format(new Date(2011,1,1), "D");
var numericValue = $.format(12345, "n0");

You can use the following snippet of code to retrieve all the available and supported cultures and then use them to populate a select list.

var selectAllCulturesObj = $("#drpListCulture").get(0);
        selectAllCulturesObj.options.length = 0;
        $.each($.cultures, function () {
            selectAllCulturesObj.options[selectAllCulturesObj.options.length] = new Option(this.englishName, this.name);
        });

Also, you can design and implement jQuery widgets that can work with varying cultures using the jQuery Globalization plugin seamlessly.

Suggested Further Reading

Summary

The official website for jQuery states:"jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid Web development. JQuery is designed to change the way that you write JavaScript."

The jQuery Globalization plugin helps you to localize your Web applications. In this article we discussed how we can work with the jQuery Globalization Plugin.



Original: February 7, 2011


[prev]