A easy way to do data formatting in Javascript


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: A easy way to do data formatting in Javascript

  1. #1
    Join Date
    Jan 2007
    Posts
    3

    A easy way to do data formatting in Javascript

    If you want to format the output in Javascript, you must realize your codes by yourself because there are no related functions in Javascrip. These days, I got a set of functions written in Javascript to realize the data formatting coded by AJAX WebShop (You can dowonload AJAX WebShop in theire official site: http://www.joyistar.com. Version 3 is recommended). They are very helpful.

    Find “system.js” in the directory of AJAX WebShop and you will get these functions below:


    --------------------Start--------------------------------
    function FormatFloat(value,mask)
    {
    return BasicFormat(value,mask,'FormatNumber')
    }
    function FormatDate(varDate, bstrFormat, varDestLocale)
    {
    return BasicFormat(varDate,bstrFormat,'FormatDate',varDestLocale);
    }
    function FormatTime(varTime, bstrFormat, varDestLocale)
    {
    return BasicFormat(varTime,bstrFormat,'FormatTime',varDestLocale);
    }
    function BasicFormat(value,mask,action,param)
    {
    var xmlDoc;
    var xslDoc;
    var v='<formats><format><value>'+value+'</value><mask>'+mask+'</mask></format></formats>';
    xmlDoc=parseXML(v);

    var x;
    if(isIE)
    x='<xsl:stylesheet xmlns:xsl="uri:xsl">'
    else
    x='<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">';
    x+='<xsl:template match="/">';
    if(isIE) {
    x+='<xsl:eval>'+action+'('+value+',"'+mask+'"';
    if(param)x+=','+param;
    x+=')</xsl:eval>';
    }
    else
    x+='<xsl:value-of select="format-number('+value+',\''+mask+'\')" />';

    x+='</xsl:template></xsl:stylesheet>';
    xslDoc=parseXML(x);
    var s;
    if(isIE)
    s= xmlDoc.transformNode(xslDoc)
    else{
    //for mozilla/netscape
    var processor = new XSLTProcessor();
    processor.importStylesheet(xslDoc);
    var result = processor.transformToFragment(xmlDoc, xmlDoc);
    var xmls = new XMLSerializer();
    s = xmls.serializeToString(result);
    }
    return s;
    }
    ----------------------------End-------------------------------------

  2. #2
    Join Date
    Apr 2007
    Posts
    3
    Great help, thanks.

Similar Threads

  1. processing additional data when program is running
    By Ervin Rodriguez in forum Database
    Replies: 1
    Last Post: 05-16-2003, 09:45 AM
  2. OVERSEAS Online Data Entry Information
    By jai in forum Careers
    Replies: 0
    Last Post: 02-21-2003, 12:43 AM
  3. Is inheritance overrated?
    By Phil Weber in forum .NET
    Replies: 67
    Last Post: 12-15-2002, 02:37 AM
  4. Parameterized Data Report? NOT easy!
    By Larry Woods in forum VB Classic
    Replies: 0
    Last Post: 11-19-2000, 10:22 AM
  5. Passing data to a cgi written in javascript
    By Jerry in forum authorevents.appleman
    Replies: 2
    Last Post: 04-13-2000, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center