Pages

Search This Blog

Tuesday, 7 January 2014

Convert JSON Date to the format MM/DD/YYYY

When searching for a way to convert the JSON date to format MM/DD/YYYY, I came accross the below code and this is not coded by me. Hope this post will help few who are still searching.

var newFormattedDate = ConvertJsonDateString(installDate);
$('#datepicker').val(newFormattedDate);


//function definition
function ConvertJsonDateString(jsonDate) {
             var shortDate = null;
             if (jsonDate) {
                 var regex = /-?\d+/;
                 var matches = regex.exec(jsonDate);
                 var dt = new Date(parseInt(matches[0]));
                 var month = dt.getMonth() + 1;
                 var monthString = month > 9 ? month : '0' + month;
                 var day = dt.getDate();
                 var dayString = day > 9 ? day : '0' + day;
                 var year = dt.getFullYear();
                 shortDate = monthString + '/' + dayString + '/' + year;
             }
             return shortDate;
 }  

jQuery to loop through a DropDown and change the Selected Index

In this example we will see how to loop through all items in a DropDown (HTML Select) and change the Selected Index when a particular condition is met. There will be cases where an index change has to be triggered explicitly which in turn loads the data for second DropDown. These expectations will be met in this post.

HTML Select Element:

<select id="ddlCars" runat="server">
     <option>Volvo</option>
     <option>Saab</option>
     <option>Mercedes</option>
     <option>Audi</option>
</select>


jQuery to change Selected Index and trigger change event

var carToBeSelected = "Mercedes";
$('#ddlCars option').each(function () {
                 var item = $(this).val().toString();
                 if (item == carToBeSelected)

                {
                     $(this).attr("selected", "selected");  //select the current item                                     $('#ddlCars').trigger('change');  //explicit trigger of change event                                    
                 }
                 index++;

});

When any change event is associated with the DropDown that piece of code will be executed when trigger('change') is triggered.

When all the items in a DropDown is associated with a value attribute then the following one line of code will do the trick.

<select id="ddlCars">
     <option value="volvo">Volvo</option>
     <option value="saab">Saab</option>
     <option value="mercedes">Mercedes</option>
     <option value="audi">Audi</option>
</select>


$('#ddlCars').val("mercedes");

Monday, 6 January 2014

jQuery/Javascript to hide and make the controls visible

For some users the controls should not be visible. For instance only the administrator user should have approve access and for other users the approve option should not be visible. In this case the following sample will help:
 <input id="approve" type="button" class="btn btn-primary" runat="server" style="visibility:hidden; background-color:#688A08" value="Approve"/>

The above html code is for a button and it is not visible while page load. To make it visible at run time using Javascript the following will help:

document.getElementById("approve").style.visibility = 'visible';

jQuery to disable html controls (Label, Text box, Dropdown, etc.,)

There will be scenarios where you want your html controls (say label, button, text box, drop down) to be disabled. The following code does the trick.
 <input type="text" id="txtCustomerName" runat="server" />

$('#txtCustomerName').prop("disabled",true);

Add Hours to a DateTime object

This post is about adding some hours to a DateTime object. For instance when the time is 12.00 am and if you wish to add 23 hours the following code snippet can be used for reference. The below code gets the current date with time and adds 23 hours

DateTime today = DateTime.Now;today = today.AddHours(23); 

Friday, 7 September 2012

ANDROID APP - Fonalyzer

Click to download Fonalyzer App

This app helps user to know the number of calls made, received and missed in the current day, in past 15 days and in past 1 month. This app can also be used to identify the memory used and level of battery. The greatest advantage is that the user can view all these details in one streamlined interface.

Screenshots:




Sunday, 2 September 2012

CREATING, USING AND TESTING SD CARD IN ANDROID EMULATORS

App developers can rely on android emulators to test their application which uses SD-card. Here are the steps which are required to create SD card in emulators.

Step 1: Open Android AVD (Android Virtual Device) Manager.
Step 2: Select the device and click Edit
Step 3: In SD Card panel enter size for memory card say 500MB and File field is optional which is the location for SD card image file.
Step 4: In Hardware panel click new and select SD Card Support property.
Step 5: Click Edit AVD.

To check whether SD card is created or not follow the below steps:
Step 6: Open Eclipse
Step 7: Keep emulator running
Step 8: Now click Window->Short View->Other->Android->File Explorer
Step 9: Navigate to mnt->android->sdcard folder using file explorer loaded at the bottom
Step 10: Add/remove files to SD card using PUSH buttons at the top of file explorer panel.