Monday, 27 May 2013

About Cookies



Authour:I will teach you courses online

C Language C++ Asp.net VB.net Oracle Hardware and Networking MCSE
Contact: Name: Shrinivas Mobileno:919703619391 E-mail: vas.shrinivas002@gmail.com


Monday, 20 May 2013

Event handler

Authour:I will teach you courses online

C Language C++ Asp.net VB.net Oracle Hardware and Networking MCSE
Contact: Name: Shrinivas Mobileno:919703619391 E-mail: vas.shrinivas002@gmail.com

Authour:I will teach you courses online

C Language C++ Asp.net VB.net Oracle Hardware and Networking MCSE
Contact: Name: Shrinivas Mobileno:919703619391 E-mail: vas.shrinivas002@gmail.com





 <html>
<title> Hear onClick event handler runs before the linked page("http://www.amcda909.com/") is loaded into the browser.

This is useful for making links conditional or displaying a 
message before launching the linked page. 
</title>
 <body>

<a href="http://www.amcda909.com/"
onClick="alert('Your are about to leave this site.');">click Here</a>


</body>

</html>

JavaScript Syntax Rules

Authour:I will teach you courses online

C Language C++ Asp.net VB.net Oracle Hardware and Networking MCSE
Contact: Name: Shrinivas Mobileno:919703619391 E-mail: vas.shrinivas002@gmail.com
Case Sensitivity

Almost everything in JavaScript is case sensitive

A). JavaScript keywords, for and if are always lowercase.

B). Builtin objects Math and Date are capital

C). DOM's are usually lowercase.

D).Blank spaces are ignored by JavaScript

Comment
// this is comment
If you want to write before writing any program like adding of two numbers. Use two forward slashes(//).

// adding of two numbers.

If you like to comment more than a single line use this

/*
This program works like calculator it
will add  numbers or multiply numbers or div numbers
and also this will works like scientific calculator
and it has much more functional ties.
*/

See above in between (/*    */) I have added more lines.




Basic Concepts of Javascript

Statement- A statement ends with semicolon, Statement is typically a single line of js, It's not a rule to break statement across multiple lines.

Examples

hours=now.getHours();
mins=now.getMinutes();
sec=now.getSeconds();


Functions:



See my previous post about Functions(Freind-add, freind-subtract):

http://javascriptwithshrinivas.blogspot.com/2013/05/about-objects.html

Functions means you assigned task, That will accomplished by functions

document.write("Wish");

Above display output to web page.


and some functions return a value

ext=prompt(" Enter some text");

Above prompt function ask you to enter some text. That text stored in ext variable.



You can also create your own functions. To avoid re coding in program, See previous post Friend-add
You can use (call) this function more times.

Objects: See my previous post
http://javascriptwithshrinivas.blogspot.com/2013/05/about-objects.html

JavaScript supports 3 kinds of objects


1).Built-in objects: JavaScript has some built in objects Like Date () ... etc. Built-in means you need not to implement anything just use it. Date () is best example.

2).DOM: Many times we used document.Write function.
In this write is method and document is object (write method belongs to document object).
We can use various components of HTML and BROWSER. Best example is alert method. It's method of window object

3). Custom objects:- Your own creation.

If else statements:


if (count==1) alert(" The countdown has reached. ");;

Above if count increases to 1 then popup box display with above message 
else not(if count==0)

Loops

for(i=1;i<=5;i++)
{
Alert("Hi. Welcome to http://javascriptwithshrinivas.blogspot.in/");

}





















Friday, 17 May 2013

More about Date object



This is Continuation from previous post
 

You now that i have allready assigned Date() object in now variable(now=new Date(); ).So I can use all methods and all 
properties of Date object in now.
You can found new line of code in this program.That is
hours=now.getHours();mins=now.getMinutes();secs=now.getSeconds();
Now i am accessing method now.getHours into hours(hours=now.getHours();)
remaining same as above mins=now.getMinutes();secs=now.getSeconds();
Below is for output
document.write(hours + ":" + mins + ":" +secs); copy code from below hear.------------------------------------------------------------------------
<html><head><title>Displaying Times and Dates</title></head>

<body>
<h1>Current Date and Time </h1>
<p>
<script type="text/javascript">

now=new Date();
localtime=now.toString();utctime=now.toGMTString();
document.write("<b>Local time:</b>" + localtime + "<BR>");
document.write("<b>utctime:</b>" + utctime );



document.write("<h1>");
document.write(hours + ":" + mins + ":" +secs);
document.write("</h1>");
</script>
</p>
</body>
</html>




Wednesday, 15 May 2013

About Date() object


Till now you red abt Objects
  Now  we are going to use Date (); object
  now= new Date();
 You can ask what is this now and new date ();
 Hear I am assigning Date() Methods and properties to now variable.

Below example you can find new tags

 document.write("<b>Local time:</b> " + localtime + "<BR>");

Explanation:<b>for bold </b>

+ for concatenation

<BR> for next line


 localtime=now.toString();
 utctime=now.toGMTString();

Above toString() and toGMTString() are methods,As i explained freind-add(),freind-subtraction in previous example.

  Copy code from below(<html>tag) and paste it to notepad save it as thrid.htm run it.
  <html>
 <head>
 <title>Displaying Times and Dates </title>
 </head>
  <body>
 <h1>Current Date and time </h1>
  <p>
  <script type="text/javascript">
 now=new Date();
 localtime=now.toString();
 utctime=now.toGMTString();
  document.write("<b>Local time:</b> " + localtime + "<BR>");
 document.write("<b>UTC time:</b> " + localtime);
   </script>
 </p>
 </body>
  </html>

http://javascriptwithshrinivas.blogspot.com/2013/05/more-about-date-object.html

Tuesday, 14 May 2013

Lesson1:First understand this then start learning javascript



Your first HTML program

How to run above program
Start->enter "notepad" without quotes in search box......................................................
now you can see notepad, click on that write above program. Save it as myfirst.htm run it.


Below you can see explanation

Advice:My personnel advice to users


A note to users before learning any new Language. It’s better to learn c and c++, then start new language you will became master in any programming language. Your life is comfortable

 Without learning these languages, Try to learn other Lang’s worthless.


VAS.SHRINIVAS, M.sc(It),MCSE, (IT)-Dept
Programmer/System admin.
Venkat Nagar,
Kakinada.

Under stand for loop Do loops





How to implement Loops

Let me explain basics

Their are three important loops are there: for,do,while.

For loop we use mostly in JavaScript, Hence I took this example.

Example programs in c language

for(i=1;i<=2;i++)
{
printf("Message for you ");
printf("\n");
}

Actually for loop is Algorithm, It will satisfy our needs.

How to understand this

Iteration1: i=1 -------------> ;1<=2 ------------> Condition satisfied ;Hence first time no increment

on Screen:Message for you

Iteration2: Now observe this two only(  ;i<=2; i++)
From Iteration2 it will start from last
i++---> You increment i, It contains 1 in previous Iteration, becz increment i=2

Now

2<=2 condition satisfied

on Screen:Message for you

Iteration3: Again  observe this two only(  ;i<=2; i++)

i++  -->You increment i, It contains 2 in previous Iteration, becz increment i=3

Now

3<=2 Condition not satisfied

exit from loop no on Screen message

on Screen
----------------------
Message for you
Message for you

If you are not understood FOR LOOP above please follow this, I have created easy way
http://javascriptwithshrinivas.blogspot.com/2013/06/how-to-understand-for-loops-in.html



If and Multiple if and Else Statements


This is most adventures feature in computer languages compare values.

About IF: 
If anybody ask your cvv number, Don't give it. 
Hear you got doubt what is cvv number, Flip your ATM card you can found cvv number.

Hear you can found two statements one is 

1 statement:If anybody ask your cvv number:is rule
2 statement:Don't give it: is action

if statement in javacript:

if(a==1) window.alert("Found a 1:");

First it checks the condition if equal(a==1) 
then message to user Found a 1:

if(a==1){

window.alert("Found a 1:");

}

Understand above code:

It checks value in variable "a", if "a: contains number 1 then message to user Found a 1:

if not  message will not displayed. That is "Found a 1".


Conditional Operators:

Condition statement uses it's own conditional operator [==,<,> these are called operators]

A conditional expression usually includes two values like this
if(a==1)----> Hear "a" and  "1" are two values.

These values can be variables, Constants.

Below operators will tell you how to compare two values

==   Is equal to
!=     Is not equal to
<      Is less than
>     Is greater than
>=  Is greater than or equal
<= Is less than or equal to


Combing conditional operators and Logical operators:

If we don't use Logical operators what happens see below


if(state == " ") window.alert("error");

if(email==" ") window.alert("error");

Using a logical operator we can combine above two statements

if(state ==" " || email==" ") window.alert("error");

This is called "||" OR operator.


how to use ||

A:
if(state ==" " || email=="abc@gmail.com") window.alert("That's OK");

B:

if(state =="Detroit " || email==" "
window.alert("That's OK");

Observe above two A: and B: if one condition is satisfied you will see "That's OK" message. Either one should satisfy then only you can see message "That's OK".


This is called smart coding single line


But sometimes both[or all] conditions should be satisfied then you can use "&&" operator.

if(state ==" " && email==" ") window.alert("error");


Observe above both conditions should satisfy then only you can see window.alert("error");
Real time example: While filling up for new mail-id some sites not allows leaving blanks in text boxes, they will show "*" symbol means compulsory.


Now analyze yourself when to use OR or when to use AND operators.

Next Logical operator is!

if(!(phone = = " ")) 
alert("phone is ok");

Above if phone number variable contains value then only statement excuted that is alert("phone is ok  "); Now you can see alert phone is ok

Alternatively you can write above condition like this

if(phone !=" ")
 alert("phone is ok"); 

IF and ELSE:


IF YOU ARE NOT UNDERSTOOD IF CONCEPT PLEASE GO DOWN YOU CAN UNDERSTAND VERY EASILY:

AFTER READING BELOW EXPLANATION,YOU CONCLUDED THAT IT'S VERY EASY IF , Again don't add me in your fans list. I am getting mails your way of explanation is very easy and understandable. This is my new invention by telling story you can understand very easily.

i MAKE PROGRAMMING IS VERY EASY.





http://javascriptwithshrinivas.blogspot.com/2013/06/how-to-understand-if-and-else.html






---------------------------------------------------------------
This two weeks i am dedicated this page to uttarakhand victims

http://someusefulltips.blogspot.in/2013/06/person-finder-2013-uttarakhand-floods.html














More about Built-in Objects





How to simplify Scripting with Objects


About objects

About objects


Every object has certain Methods and properties


Methods:

I want to give practical example, Friends are best example for Methods, and if u asks something they will do.

Technically you ask u r friend please add   

int x=5,y=3;
(Now u r calling): freind-add(int x,int y);


Freind-add (int x, int y)
{

int c=x+y;

printf("%d",c);

}

he completed adding.
Note: Above example assume u r freind name is freind-add

similarlly you ask u r freind please subtract (Now u r calling):

int x=6, y=3;

(Now u r calling):freind-subtract(int x,int y)

freind-subtract(int x,int y)
{

int c=x-y;

printf("%d",c);


}

Another freind completed subtracting.

In java script you can see objects like button, textbox .... these are called objects.similarly button has some methods.

Click,Double click are some methods for button object

About Properties

These buttons has some properties: Height,Width,back color

Properties means it defines about object.How they look like.

See like human beings i am tall(6 feet),good eyes(Blue eyes) ... these are called 
properties




Using Functions

Functions:-
Below will teach you about functions
http://javascriptwithshrinivas.blogspot.in/2013/05/about-objects.html

Functions:  Functions are useful to reuse code; we can call n number of times to use code.
copy code from below

<html>

<head>

<title>Functions</title>

<script type="text/javascript">

function meet(who) {

         alert("Greetings, " + who);
                   }

</script>

</head>

<body>

<h1>Function example </h1>

<script type="text/javascript">
meet("Great");
meet("Shrinivas");
</script>
</body>
</html>

---------don't copy this line-End above---------------------------------

Explanation:

meet ("Great"); after calling like this, meet function pass "Great" string to meet function assign to whom, now alert display Greetings Great

Next same process repeated display

Greetings Shrinivas

Returning a Value example:

What is difference between above function and Returning a Value example is 
Above function will just display message to user and this Returning a value example return a value to script.

Below example Returning a Value example:
<html>

<head>

<title>Functions</title>

<script type="text/javascript">

function Average(a,b,c,d,e) {

result =(a+b+c+d+e)/5;
return result;
              

     }

</script>

</head>

<body>

<h1>Function example </h1>

<script type="text/javascript">
score=Average(25,35,45,55,65);

document.write("The average is:" + score);

</script>
</body>

</html>








How to Implement sorting


Authour:I will teach you courses online

C Language C++ Asp.net VB.net Oracle Hardware and Networking MCSE
Contact: Name: Shrinivas Mobileno:919703619391 E-mail: vas.shrinivas002@gmail.com

First understand this:

Let us assume we taken below array

var a=["9","8","3","2","8","11","7"]

First understand this:

step1:-->if (r[i]<=r[j])

          t=t+1;

Above array 11 is biggest number,Based on above condition t will return
zenrate:t=1 for Highest no 11
        t=2 for second biggest no 9
        t=3 for third biggest no 8
        t=4 for fourth biggest no 7
        t=5 for fifth biggest no 3
        t=6 for least no---------2

Now i am inserting highest number in last of array index that b[5]=r[i]


not understand see this b[5]=11,b[4]=9,b[3]=8,b[2]=7,b[1]=3,b[0]=2



Don't forget this is the key for writing sorting order



Order in this way:

Display in Ascending Order:a=["9","8","3","2","8","11","7"]



for(i=0;i<=4;i++)
{

document.write(b[i]);--->out put in this order 2,3,7,8,9,11
}

Also,If u want display in Descending Order this code will help you how


for(i=4;i>=0;i--)
{
document.write(b[i]);--->Out put is 11,9,8,7,3,2
}
----------------------------------------------------------------------------------
Next you can change below code in your environment(c,c++,c#,java,Google Apps)

By understanding above algorithum you came to know that how to implement algorithums

Authour:I will teach you courses online

C Language C++ Asp.net VB.net Oracle Hardware and Networking MCSE
Contact: Name: Shrinivas Mobileno:919703619391 E-mail: vas.shrinivas002@gmail.com

My own sorting-Below is sample program how to implement sorting



<html>

<script type="text/javascript">

var r=new Array();

r[0]=1;
r[1]=237654;
r[2]=99999;
r[3]=99;
r[4]=10000;



var b=new Array();

var t=0;

document.write("Given format"+r);

document.write("<br />")

for (i=0;i<=4;i++)
{

    for(j=0;j<=4;j++)

          {


     if (r[i]<=r[j])
            {

        t=t+1;
       

            }
 
         }


if (t==1)
{
b[4]=r[i];
document.write(" Highest no"+b[4]+"<br /> ");

}

else if(t==2)
{
b[3]=r[i];
document.write("second highest no"+b[3]+"<br /> ");

}

else if(t==3)
{
b[2]=r[i];
document.write("Third highest no"+b[2]+"<br /> ");

}

else if(t==4)
{

b[1]=r[i];
document.write("Fourth highest no"+b[1]+"<br /> ");

}


else if(t==5)
{
b[0]=r[i];
document.write("Least no"+b[0]+"<br /> ");

}


t=0;
}



document.write("Output in Ascending order:")



for(i=0;i<=4;i++)

{
document.write(b[i]+" ");
}        






</script>

</html>





Using Numeric Arrays/String Arrays


How to use String Object

Authour:I will teach you courses online

C Language C++ Asp.net VB.net Oracle Hardware and Networking MCSE
Contact: Name: Shrinivas Mobileno:919703619391 E-mail: vas.shrinivas002@gmail.com

Data Types and Converting Between Data Types


Expressions and Operators


Using Variables

Authour:I will teach you courses online

C Language C++ Asp.net VB.net Oracle Hardware and Networking MCSE
Contact: Name: Shrinivas Mobileno:919703619391 E-mail: vas.shrinivas002@gmail.com
About Variables:

Let us come to real world today you purchased a BAT or TV. You need a place to put these objects in your house. Meaning these objects are occupying some place in your house.

 Like this assume that BAT equals to 5 AND TV equals to 6 now today you purchased these numbers in market. Then you went to your home. You need a place to put this numbers in your computer so decided to put 5 in a and 6 in b. Now it's look like below

a=5 b=6

In java script to use any variable they use var keyword before variable. You can omit var in many cases. To understand where to declare a variable, we need to understand the concept of scope. 

If you declare a variable within the function, It will available only for function they are created in.

student=1;

Above is called local variable. Within the function you can use this variable
If you declare a variable outside of function or declared in main script, You can use throughout the script.

var student=1;


Assigning Values to Variables:

You all ready now that assigning values to variable see above

a=5 b=6 example

Increment procedure:

a=a+1;

a contains 5
a=5;

Above works from right to left, Not understood see this

first 5+1-->6

now a contains 6;

Equivalent of a=a+1 is a +=1;

Equivalent of a=a-1 is a -=1;

If u feel it's hard you can use this a++; for increment

a--; for subtraction

Operators in java script:

+ for Concatenate

+ Add
-  Subtract
* Multiply
/ Divide
% remainder
++ Increment
-- Decrement


Operator Precedence:

When you use more than one operator in an expression, JavaScript uses rules of operator precedence to decide how to calculate the value.

See example below

result=2+5*3;

above will give two results 1). 21-----2+5:7*3=21

                                      2). 17-----5*3:15+2=17


Which one is correct !!! 
In above situation java Script uses RULES. It will give higher precedence to multiplication then addition.

First multipication:5*3=15
second addition:2+15=17

See another problem

a+b+c+d/4

Above you think it will add a+b+c+d after that it will divided by 4

You think wrong:

Divided by gives higher precedence, D value is divide by four then add with other 3 numbers a,b,c;

solution for above problem is:

result=(a+b+c+d)/4;

Parentheses ensure that the four variables are added first, and then the sum is divided by four.

Data Types in JavaScript:

Numbers: Javascript supports both Integers[3,4,5] and floating point numbers[1.2333]

String: One or more characters of text is called String "I am great"

Boolean: These can have one of two values: true or false. More later

null value: Represented by the keyword null.

Converting Between Data Types


JavaScript handles conversions between data types for u whenver it can for example:

total=34;
document.write("The total is" + total);

Above print The total is 40, Because document.write function works with strings.
The JavaScript interpeter automatically converts non strings to string before performing the function.

Note: Did u understand above Interpeter works first.

But some times you will get problems

total=34 comes after 

avg=total/3;

What to do now?????

Because total is not number it's both integer and string.

We need to convert it to a regular numeric variable.

Js(JavaScript)contains two functions for this

parseInt()-Convert a string to an integer number.

parseFloat()-Converts a string to a floating point number.


Both of the functions reads numeric from string and return number.

stringvar="25 says bye";

numvar=parseInt(stringvar);


Above parseInt reads numeric from string "stringvar", it contains 25. Now 25 will return to numvar.

store=numvar/5; Now no problem with numvar contains 25.

contd .....

Creating a String object

There are two ways to create a new String object. The first is the one u know.Second is object oreinted.

store="This is only a example";

store = new String("This is only a example");


Example on Assigns values to Strings and Combining them
test1="Welcome to ";

test2="ABC pvt Ltd.,";

combined=test1+test2;


U can easily understand test1, test2 then what is combined variable. I have combined test1 and test2 with "+"[concatenation].Assigned into combined variable

copy code from below
----------------------------------------------------------------------------------------------------------
<html>

<head>

<title>String Test</title>

</head>


<body>

<h1>String Test </h1>

<script type="text/javascript">

test1="Welcome to ";

test2="ABC pvt Ltd.,";

combined=test1+test2;

alert(combined);

</script>

</body>

</html>
---------------------------------------------------------------------------------
Calculating string length

To count string length, We use length property

explanation on length:

tot="A leader will help society";

document.write(tot.length);

Example on length:

<html>
<head>

<title>to count lenght of string </title> </head>

<body>



<script type="text/javascript">


test="A Leader all ways work for society";

document.write(test.length);


</script>


</body>

</html>
--------------------------------------------------------------------------
Converting the String's Case:
To methods of the String object enables to convert string to lower or uppercase.

toUpperCase()-converts all characters to uppercase.

toLowerCase()-converts all characters to lowercase.

<html>
<head>

<title> Convert to uppercase </title>  </head>


<body>

<script type="text/javascript">

test="a man can do anything";


document.write(test.toUpperCase());


</script>



</body>

</html>
-------------------------------------------------------------------------------------------
Replace toUpperCase with toLowerCase, for lowercase.


Working with Substrings

Sometimes you want to read 2 or more letter from a string. then you can use Substring method.

test="Internetexplorer";

document.write(test.substring(3,6));

Count starts from 0(zero) left letter 3 that is [e] return up to 6th letter: ern
------------------------
Getting a single Character:

charAt method is a simple way to grab a single character from a string.

ex: arrived

alpha.charAt(0) returns a

alpha.charAt(5) returns e

Finding a Substring


In a given string you want to search for a particular string Like below
Ex:My name is not what u expect my name is shrinivas
Another use for substrings is to find a string within another string. One way is indexOf method.

test=” My name is not what u expect my name is shrinivas”;
loc=test.indexOf(“shrinivas”);
Now the value returned in the loc variable is and index into string. You that first character of the string is index 0(zero).

Now you understood everything. If multiple occurrence of strings what you will do???

Ex:My name is not what u expect my name is shrinivas

Like ex: Occurrence of name 2 times.

loc=temp.indexOf("name",3);


Use of second parameter is to search for multiple occurrences of string. After found the first string

Numeric Arrays:

Array: Array means, Today u decided to multiply 5 with these numbers 25,56,78,90.

In a ordinary program you take 4 variables (a=25, b=56, c=78, d=90) to multiply with 5
  Instead of declare 4 variables individually, you can use arrays.

<html>
<head>
<title>Multiplecation with 5 </title> </head>


<body>
<h1>Multiplecation with 5<h1>
<script type="text/javascript">

a=new Array(3);
b=5;

a[0]=25;
a[1]=56;
a[2]=78;
a[3]=90;

for(i=0;i<=3;i++)

{

a[i]=b*a[i];

document.write(a[i]+"<BR>");


}


</script>

</body>

</html>



You might be ask what is the advantage of taking arrays.
see if i take a=25, b=56, c=78, d=90 four variables
Advantages of useing ARRAYS:

1).These four variables store in different locations[Not a contiguous], It will take a little more time to fetch data. If you use ARRAYS process is very fast[Because data in contiguous location].

2).U can store multiple properties like Author: a[o]="Author FirName";
                                                                       a[1]="Author Sir name";
                                                                        a[2]="Phone number";
                                                                        a[3]="Street name";  
                                                                         a[4]="State";
                                                                         a[5]="Dist";




Accessing Array Elements:
a[0]=25;
a[1]=56;
a[2]=78;
a[3]=90;


for(i=0;i<=3;i++)

{



document.write(a[i]+"<BR>");


}

In above code :

First iteration zero will come a[0] then print 25

Second iteration 1 will come a[1] then print 56

third iteration 2 will come a[2] then print 78

so onnnnnnnnnnnnn...
copy code from below


<html>
<head>
<title>Contents of array </title> </head>


<body>
<h1>Contents of array<h1>
<script type="text/javascript">

a=new Array(3);
b=5;

a[0]=25;
a[1]=56;
a[2]=78;
a[3]=90;

for(i=0;i<=3;i++)

{



document.write(a[i]+"<BR>");


}


</script>

</body>

</html>


Creating a String Array: You can declare string array like numeric array.



fullnames= new Array(30);


You can assign string values.

fullnames[0]="Taj Mahal";
fullnames[1]="India is a great place";
fullnames[2]="civilization started their";

Splitting a String:


name="Great Vas Shrinivas";
chop=name.split(" ");

In this example split function splits the name string into three arrays.

chop[0]="Great"
chop[1]="Vas"
chop[2]="Shrinivas"


Opposite to split is join:Meaning you can joing array into one string.

fullname=chop.join(" ");



Sorting Numeric array: Sorting is my interesting topic.

Below example javascript uses

function numcompare(a,b)
{

return a-b;

}

nums = new Array(30,10,200,4);

sortorder=nums.sort(numcompare);



Output:4,10,30,200

Above is ordinary you can implement your own sorting by understanding my examples

First understand this

http://javascriptwithshrinivas.blogspot.com/2013/05/how-to-implement-sorting.html
Next try to understand this, It's very easy.


http://javascriptwithshrinivas.blogspot.com/2013/05/my-own-sorting.html



Above code you can change as per your requirements.