Monday, February 2, 2015

Javascript Calculating the sum of the digits

<SCRIPT>
function sumDigits(num) {
     var i, sum = 0;                  // can declare two variables at once
     for (i = 1; i <= num; i++) {
             sum += i;              // add each number to sum (ie, 1 + 2 + ...+ num)
     }
     // Display result
     alert("The sum of the digits from 1 to "+ num + " is:\n\n\t " + sum);
}
</SCRIPT>
<BODY>
Looping Functions - Calculate the sum of the digits.
<FORM NAME="SumNums">
     The sum of the digits from 1 to:
     <INPUT TYPE="text" NAME="charNum">
     <INPUT TYPE="button" VALUE="Calculate"
       onClick="sumDigits(SumNums.charNum.value)">
</FORM>

Javascript Bouncing Ball Example

Link - http://www.sislands.com/coin70/week3/bball.htm


This script uses a the setTimeout() Method to perform a sequence of Image Swaps that create the animation.
The setTimeout() Method accepts two arguments, the name of a Function that you want to call and the number of milliseconds you want to wait before calling the Function. The name of the Function needs to be in "quotes", so it looks like this:
setTimeout("someFunction()", 100);
This example waits 100 milliseconds (one tenth of a second) and then calls "someFunction()".
So, this animation is composed of 5 different images of the ball dropping. Each image is about 300 pixels tall, which is the length that the ball drops. In other words, the image never changes position or size, the ball just changes location in each successive image.
As is the standard when doing an image swap, all five of the ball images are Pre-loaded into Image Objects. In this case, each of the image Objects is also loaded into an Array, which makes it easy to refer to them in the script. This process of Pre-loading the image works like this:
var imageArray = new Array();
imageArray[0] = new Image();
imageArray[0].src = "images/ball0.gif";
imageArray[1] = new Image();
imageArray[1].src = "images/ball1.gif";
etc.
To make the ball drop, there is a Function called bounce() which contains a series of setTimeout() Methods that call each of the five images as the ball drops and then calls each of the five images in reverse order as the ball bounces back up. The setTimeout() Methods have longer and longer time intervals specified. The whole series looks like this:
function bounce() {
     setTimeout("document.images['ball'].src = imageArray[0].src", 100);
     setTimeout("document.images['ball'].src = imageArray[1].src", 200);
     setTimeout("document.images['ball'].src = imageArray[2].src", 300);
     setTimeout("document.images['ball'].src = imageArray[3].src", 400);
     setTimeout("document.images['ball'].src = imageArray[4].src", 500);
     setTimeout("document.images['ball'].src = imageArray[5].src", 600);
     setTimeout("document.images['ball'].src = imageArray[4].src", 700);
     setTimeout("document.images['ball'].src = imageArray[3].src", 800);
     setTimeout("document.images['ball'].src = imageArray[2].src", 900);
     setTimeout("document.images['ball'].src = imageArray[1].src", 1000);
     setTimeout("document.images['ball'].src = imageArray[0].src", 1100);
}
This Function takes almost no time to finish, all of the setTimeout() Methods themselves are executed in less than 15 milliseconds. But the commands that they call, which are all image swaps, occur over a 1.1 second time interval because the setTimeout() Methods have specified it that way.
As we'll see in a later class, it's not good to call more than 20 setTimeout Methods at once. It swamps JavaScript and you'll get an error message.

Tuesday, January 27, 2015

Sharepoint 2013 deploy app through wsp and activate feature


1) site settings - solutions - upload wsp by clicking upload solution - Activate App

2) site settings - site actions - manage site features - Activate app

Wednesday, December 17, 2014

Counting occurences of Javascript array elements

var arr = [2, 2, 2, 2, 2, 4, 5, 5, 5, 9];

function foo(arr) {
    var a = [], b = [], prev;
   
    arr.sort();
    for ( var i = 0; i < arr.length; i++ ) {
        if ( arr[i] !== prev ) {
            a.push(arr[i]);
            b.push(1);
        } else {
            b[b.length-1]++;
        }
        prev = arr[i];
    }
   
    return [a, b];
}

var result = foo(arr);
document.write('[' + result[0] + ']<br>[' + result[1] + ']')

[2,4,5,9]
[5,1,3,1]

Monday, December 8, 2014

asp.net pie chart hide image or change background color to transparent

1 ) Image 1


2) Image 2
 3) Code

   <asp:Chart ID="Chart1" runat="server" Height="200px" Width="300px" OnClick="Chart1_Click"
                                BackColor="Transparent" PageColor="Transparent">
                                <Titles>
                                    <asp:Title ShadowOffset="3" Name="Items" />
                                </Titles>
                                <Series>
                                    <asp:Series Name="Default" />
                                </Series>
                                <ChartAreas>
                                    <asp:ChartArea Name="ChartArea1" BorderWidth="0" BackColor="Transparent">
                                        <AxisX>
                                            <MajorGrid Enabled="False" />
                                        </AxisX>
                                        <AxisY>
                                            <MajorGrid Enabled="False" />
                                        </AxisY>
                                    </asp:ChartArea>
                                </ChartAreas>
                                <Legends>
                                    <asp:Legend Alignment="Center" Docking="Right" IsDockedInsideChartArea="false" IsTextAutoFit="true"
                                        Name="Default" LegendStyle="Table">
                                    </asp:Legend>
                                </Legends>
                            </asp:Chart>

Wednesday, December 3, 2014

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode

In your web.config, make sure these keys exist:

<configuration>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
    </system.webServer>
</configuration>

Tuesday, December 2, 2014

asp.net dropdown add select option

   if (dsRiskCategories.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = dsRiskCategories.Tables[0].NewRow();
                    dr["CategoryId"] = "0";
                    dr["CategoryName"] = "Select Risk Category";
                    dsRiskCategories.Tables[0].Rows.InsertAt(dr, 0);
                }

                ddlCategory.DataSource = dsRiskCategories;
                ddlCategory.DataTextField = "CategoryName";
                ddlCategory.DataValueField = "CategoryId";
                ddlCategory.DataBind();