Wednesday, September 8, 2010

JavaScript Trim Functions

A JavaScript string function does not have in built string trimming functions available. Hence we found following codes when we Google it out on the net. To save your time in searching for required string trimming functions we consolidated all the information we got from the net.

The first is a definition of the seperate function ltrim, rtrim and trim. These trim the spaces to the left of the string, the right of the string and both sides respectively.

function trim(s)

{

return rtrim(ltrim(s));

}

function ltrim(s)

{

var l=0;

while(l <>

{ l++; }

return s.substring(l, s.length);

}

function rtrim(s)

{

var r=s.length -1;

while(r > 0 && s[r] == ' ')

{ r-=1; }

return s.substring(0, r+1);

}

If you are only going to use trim, you might want to use this, probably faster, defenition:

function trim(s)

{

var l=0; var r=s.length -1;

while(l <>

{ l++; }

while(r > l && s[r] == ' ')

{ r-=1; }

return s.substring(l, r+1);

}

Reference Blog: http://doc.infosnel.nl/javascript_trim.html


If you are familiar with REGEX following code will provide you more better efficiency than previous codes. This will also reduce your lines of code.

function trim(stringToTrim) {

return stringToTrim.replace(/^\s+|\s+$/g,"");

}

function ltrim(stringToTrim) {

return stringToTrim.replace(/^\s+/,"");

}

function rtrim(stringToTrim) {

return stringToTrim.replace(/\s+$/,"");

}

// example of using trim, ltrim, and rtrim

var myString = " hello my name is ";

alert("*"+trim(myString)+"*");

alert("*"+ltrim(myString)+"*");

alert("*"+rtrim(myString)+"*");

Reference Blog: http://www.somacon.com/p355.php

Always Search @ Fukat Ka Gyan: Hub For Quick Solutions

Monday, September 6, 2010

Dynamic Field Name in Custom List Form

A common problem that is normally faced while using Custom List forms or Data View Web Part is Column Name doesn’t get updated automatically in the customized form if any change is made to the Column name in the list.

For resolution of this problem use following code in place of hard coding column names in the custom list forms.

ControlMode will change based upon the form type (New, Edit and Display)

ControlMode=”New / Edit / Display”

FieldName=Internal name of the fields

References:

http://ankushg.spaces.live.com/blog/cns!12D87E23D9058350!235.entry

Always Search @ Fukat Ka Gyan: Hub For Quick Solutions

Friday, September 3, 2010

Working with Cookies

A cookie is a variable that is stored on the visitor's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With JavaScript, you can both create and retrieve cookie values.

If c_name is the name of the cookie.

Creating Cookies:
Use the following function to create a cookie,

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

Reading Cookie Value:
You can the get the values of the cookie created in the first step using the following function. You just need to pass cookie name to this function,

function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}

Deleting Cookies:
Use the following function to delete a cookie. Just pass the name to the function,

function Delete_Cookie(c_name)
{
document.parentWindow.parent.document.cookie = name + "=" + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

Always Search @ Fukat Ka Gyan: Hub For Quick Solutions

Sunday, May 30, 2010

Document Sets

To get started using Document Sets, first the Document Sets feature needs to be activated. You can do this form Site Actions > Site Settings > Site Collection Features:



Once activated, a Document Set content type becomes available to you to be added to any document library where you want to start using Document Sets:



Once you've added the Document Set content type to your library, you can create a new document set from the Ribbon by selecting the New Document > Document Set option:



When you create a Document Set you'll be prompted to provide a Name and optional description for the Document Set along with any metadata attributes or columns added to the document library. TIP: Add the Document Set content type to the library before adding any custom columns to the library to ensure the custom columns are applied to all content types supported by the library.

Once you've created your Document Set you can add documents to it just like a document library or folder by New Document or Upload Documents options from the Ribbon. You're document set should look something like this:



Whilst inside your Document Set you can edit its content and add new documents as needed, however, when viewed from the document library, your Document Set appears as a single item than you can manipulate as single entity:


This article can be found at http://blogs.bsg.co.uk/SharePoint/Lists/Posts/Post.aspx?ID=10

Always Search @ Fukat Ka Gyan: Hub For Quick Solutions



What to drink while Dieting?

When people diet they don't think carefully about what they drink – You need to though.

Eating and drinking are closely linked eat the right foods and drink the wrong drinks and you will reduce your chances of losing weight.

What are the best things to drink when on a diet?

Here we will look at the best drinks to aid weight loss and the ones that can slow down, or make your diet ineffective.

Let's look at drink and dieting and start with the best drink of all first.

1. Water

Water pure and simple is the single best drink for losing weight and is the most important catalyist for weight loss in ANY diet.

A dieter should drink at least eight glasses of water.

Water is quite possibly the single most important catalyst in losing weight and keeping it off.

It acts as a natural appetite suppressant by keeping your stomach full and fending off dehydration which can lead to hunger pangs.

Many times when you feel "hunger signals", they are actually "thirst signals", so before eating, drink a glass of water instead.

Most importantly of all, water helps your body metabolizes stored fat by helping the kidneys flush out waste.

When you don't drink enough water the liver which works to provide stored fat for energy also takes on the task of helping out the kidneys and thus becomes less effective at metabolizing fat.

Drinking eight glasses of ice cold water a day burns about 62 calories because your body has to work to raise that waters temperature to body temperature – That amounts to about 430 calories per week.

2. Alcohol and soda

When dieting, don't drink to much alcohol or sodas that are high in sugar. They contain plenty of calories and also make you feel hungry. So moderation is the order of the day.

Not all alcoholic drinks contain the same ingredients and have different affects on a diet.

Pure spirits are one of the best type of drinks to consume while on a diet because they contain approx 100 calories and very little in way of carbohydrates.

Examples would be shots of vodka, rum, Bacardi, or gin – With no mixer added.

If mixing these drinks when on a diet make sure you use diet tonic and diet cola's etc

Wine is ok in moderation and many people like a glass with their meal a typical glass of red or white is both low in carbohydrates and calories.

Don't go for sweet wines though stay with dry as they are not so fattening.

Beer is full of calories and really when dieting drink in moderation. Keep in mind that a pint of beer can contain a whopping 300 calories.

3. Coffee & Tea

Coffee is fat-free, but drinking it can be detrimental to diets why? – Because even though coffee in itself is fat-free, it is what can be added that hurts your diet.

Low and fat free milk is fine, but avoid cream. Finally, go easy on the sugar, if you have a sweet tooth.

All you have to do is remember that without added sugar or cream, coffee does not contain any calories.

Plain tea does not have any calories before you add your sweeteners and milk.

If you are looking for an option that does not contain caffeine, you may want to check out black or green tea. Many herbal teas possess a diuretic effect.

When it comes to the drinking of iced tea, you need to check the label to make sure that it contains no sugar.

4. Green Tea

A favorite diet drink is green tea.

The benefits of drinking green tea can be seen through the high concentration of antioxidants that can be found.

Studies have also shown that the benefits of green tea for dieting are visible when drinking just one cup a day and weight loss is speeded up.

5. Fruit Juices

When choosing a fruit juice while dieting, you should always look at the nutritional information found on the label.

You need to make sure that the juice is made from real fruit and not the sugar-filled concentrates that are loaded with calories. Providing the juice is natural any fruit or vegetable juice can be incorporated in your diet.

6. Milk

Milk contains calories but if used correctly in a diet can help you lose weight. Make sure that you choose low or fat free varieties that contain far less calories

One of the reasons that milk helps some to lose weight because it makes you feel full. It also aids in bone strength, as well as lowers blood pressure and provides a load of other nutrients our bodies need.

When dieting we all have to drink and the choices we make can have a big affect on how much weight we lose as you can from the above.

By all means enjoy any drink even alcohol but do so in moderation

Monday, May 17, 2010

Upgrading an Existing Master Page to the SharePoint Foundation Master Page

There have been significant changes to the user interface (UI) for Microsoft SharePoint Foundation 2010, including the addition of the . By default, the v4.master page includes the . Many of the commands previously found in menus and toolbars now exist inside of the . As a result, if your existing master page does not contain the , many commands will be unavailable. This topic shows you how to add the along with any new controls or content placeholders that are required for an existing master page to render correctly in SharePoint Foundation 2010.

Prerequisites

  • Microsoft SharePoint Foundation 2010

Controls on the Server Ribbon

There are some controls that were previously included with the default master page that have been moved into the new UI. Because these controls now exist inside the , if you plan to update an existing master page with functionality, you need to remove the following controls from your existing master page. These controls will be added when your incorporate the into your master page.

  • Publishing Console -

  • Site Actions Menu -

  • Sign-in and Log-in Control

More information about this article can be found at
http://msdn.microsoft.com/en-us/library/ee539981%28office.14%29.aspx

Always Search @ Fukat Ka Gyan: Hub For Quick Solutions