Posts Tagged ‘javascript’

So far I have been in very dilemmatic situation whether to develop a native mobile application, having a buzz in the market to have mobile app for almost every application. I always wanted to try my hands on it, but somehow I never ever could start on it. Quite a few times I did setup IDE and SDKs to develop android application, but every time I started I could not carry on.

Being a web developer, always wanted to build the mobile application which will work on all platforms, but again a mini war between these mobile giants never encouraged a common SDK on IDE to develop the same.

To start my day, I always scan through all tech newsletters, 1 week back I found one article, Cross-Platform mobile applications using PhoneGap and JQuery (HTML5 and CSS3), as always curious to know about it, clicked through the link and read the article, understood the concept and somehow liked it so much, they kept it simple but effective. I was happy, finally I could start my mobile application, and deploy it on multiple platforms.

I created one simple app, and deployed the same on both android and iPhone, worked like a charm.

Visit phonegap.com and download, its FREE, read the instructions, that should get you going.

If you combine the power of PhoneGap and jQuery mobile, I bet you can develop nice UI as well as an application with a strong backend.

Recently heard that telerik has also launched an SDK Kendo UI, same concept, but like all telerik components its a paid product. visit kendoui.com

Questions? let me know.

Node.js (nodejs.org) is an event-driven I/O server-side JavaScript environment based on V8. It is intended for writing scalable network programs such as web servers. It was created by Ryan Dahl in 2009, and its growth is sponsored by Joyent, which employs Dahl.

Wiki : en.wikipedia.org/wiki/Nodejs

Scriptographer ported to JavaScript and the browser, using HTML5 Canvas.

paperjs.org

You all must have heard about HTML5 the new standards of markups.

HTML5 is a cooperation between the World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working Group (WHATWG).

WHATWG was working with web forms and applications, and W3C was working with XHTML 2.0. In 2006, they decided to cooperate and create a new version of HTML.

Some rules for HTML5 were established:

  • New features should be based on HTML, CSS, DOM, and JavaScript
  • Reduce the need for external plugins (like Flash)
  • Better error handling
  • More markup to replace scripting
  • HTML5 should be device independent
  • The development process should be visible to the public

It reduces the amount doctypes, encoding and meta tags on your webpage, have introduced lot of new markup tags such as <article>, <canvas>, <footer>, <Video>, geolocation etc. which makes your webpage source much more understandable for the search engines.

Also, It looks much more cleaner than the HTML4 / XHTML

HTML5 development is still under progress, and expected to be a public standard by 2020 or 2022.

Most of the latest browsers have started adding HTML5 support, however all the HTML5 tags are not available till date, Google Chrome supports most of the HTML5 tags, Firefox supports few and IE supports the least.

New tags are good, but the most userful feature in HTML5 I found is the local / web storage. It is a good replacement of browser cookies to store anything at client side.

One of the common disadvantage of cookie is that they are included with every HTTP request, thereby slowing down your web application by needlessly transmitting the same data over and over.

How to use localstorage in HTML 5:

Localstorage:

<script type=”text/javascript”>

localStorage.lastname=”Smith”;

document.write(localStorage.lastname);

</script>

Sessionstorage:

<script type=”text/javascript”>

sessionStorage.lastname=”Smith”;

document.write(sessionStorage.lastname);

</script>

Try this out, so far i have tested it on IE8, mozilla FF 4.0 & 5.0, Safari, Chrome, Opera and Rockmelt, they do support this local storage feature.

For more details on HTML5 and localstorage visit:

w3schools.com/html5/html5_webstorage.asp

diveintohtml5.org/storage.html

diveintohtml5.org

In one of the module I came across to the situation where a physician needs to input their DEA number on a form and we have to validate the DEA Number, either using javascript or C#. I was provided with the algorithm from client and we had to write a javascript / c# function for the same. First I tried searching it on Google for some ready made stuff, but I could not found any, so written my own function to validate a DEA number. Here is the code snippet in both Javascript and C#:

C#
private bool DEAValidation(string DEANumber)
{
if (DEANumber != null && DEANumber != “” && DEANumber.Length == 9)
{
string strDEAFirstLetter = DEANumber.Substring(0, 1).ToUpper();
Response.Write(“strDEAFirstLetter: ” + strDEAFirstLetter);

if (strDEAFirstLetter != “A” && strDEAFirstLetter != “B” && strDEAFirstLetter != “M” && strDEAFirstLetter != “F”)
{
return false;
}

string strDEASecondLetter = DEANumber.Substring(1, 1).ToUpper();
string strValidChars = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”;
string strValidNums = “0123456789”;
if (strValidChars.IndexOf(strDEASecondLetter) < 0 && strValidNums.IndexOf(strDEASecondLetter) < 0)
{
return false;
}

int iThirdDigit = int.Parse(DEANumber.Substring(2, 1));
int iForthDigit = int.Parse(DEANumber.Substring(3, 1));
int iFifthDigit = int.Parse(DEANumber.Substring(4, 1));
int iSixthDigit = int.Parse(DEANumber.Substring(5, 1));
int iSeventhDigit = int.Parse(DEANumber.Substring(6, 1));
int iEightDigit = int.Parse(DEANumber.Substring(7, 1));
int iNinthDigit = int.Parse(DEANumber.Substring(8, 1));

int Total_3_5_7 = iThirdDigit + iFifthDigit + iSeventhDigit;
int Total_4_6_8 = iForthDigit + iSixthDigit + iEightDigit;

int FinalTotal = Total_3_5_7 + (2 * Total_4_6_8);

Response.Write(“FinalTotal: ” + FinalTotal.ToString());

if (iNinthDigit.ToString() != FinalTotal.ToString().Substring(FinalTotal.ToString().Length – 1, 1))
{
return false;
}

return true;
}
else
{
return false;
}
}

Javascript:


function DEAValidation(DEANumber)
{
try
{
if (DEANumber != null && DEANumber != “” && DEANumber.length == 9)
{

var strDEAFirstLetter = DEANumber.substr(0, 1).toUpperCase();

if (strDEAFirstLetter != “A” && strDEAFirstLetter != “B” && strDEAFirstLetter != “M” && strDEAFirstLetter != “F”)
{
return false;
}

var strDEASecondLetter = DEANumber.substr(1, 1).toUpperCase();

var strValidChars = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”;
var strValidNums = “0123456789”;

if (strValidChars.indexOf(strDEASecondLetter) < 0 && strValidNums.indexOf(strDEASecondLetter) < 0)
{
return false;
}

var iThirdDigit = parseInt(DEANumber.substr(2, 1));
var iForthDigit = parseInt(DEANumber.substr(3, 1));
var iFifthDigit = parseInt(DEANumber.substr(4, 1));
var iSixthDigit = parseInt(DEANumber.substr(5, 1));
var iSeventhDigit = parseInt(DEANumber.substr(6, 1));
var iEightDigit = parseInt(DEANumber.substr(7, 1));
var iNinthDigit = parseInt(DEANumber.substr(8, 1));

var Total_3_5_7 = iThirdDigit + iFifthDigit + iSeventhDigit;
var Total_4_6_8 = iForthDigit + iSixthDigit + iEightDigit;

var FinalTotal = Total_3_5_7 + (2 * Total_4_6_8);

if (iNinthDigit != FinalTotal.toString().substr(parseInt(FinalTotal.toString().length) – 1,1))
{
return false;
}

return true;

}
else
{
return false;
}
}
catch(err)
{
return false;
}
}