Final Css Manual 1 19
Final Css Manual 1 19
Institute,………………………………………………………………………………………………………………
Client Side Scripting languages (22519) for the academic year ………………… to
Seal of Institution
Client Side Scripting Languages (22519)
PO 3.Experiments and practice: Plan to perform experiments and practices to use the results to
solve broad-based Computer engineering problems.
PO 4.Engineering tools: Apply relevant Computer technologies and tools with an understanding
of the limitations.
PO 5.The engineer and society: Assess societal, health, safety, legal and cultural issues and the
consequent responsibilities relevant to practice in field of Computer engineering.
PO 7. Ethics: Apply ethical principles for commitment to professional ethics, responsibilities and
norms of the practice also in the field of Computer engineering.
PO 8.Individual and team work: Function effectively as a leader and team member in diverse/
multidisciplinary teams.
PO 10.Life-long learning: Engage in independent and life-long learning activities in the context
of technological changes in the Computer engineering field and allied industry.
Content Page
Total
o simple syntax
JavaScript How To
– The HTML <script> tag is used to insert a JavaScript into an HTML page
<script type=“text/javascript”>
</script>
o Optional; required when you want to put multiple statements on a single line
JavaScript can be inserted within the head, the body, or use external JavaScript file
<script type=“text/javascript”>
<!—
document.write(“Hello World!”)
// -->
</script>
JavaScript Variables
<html>
<script language="JavaScript">
alert("Hello World!");
</script>
</html>
<html>
<script language="JavaScript">
varans = 0;
varfirstnum = 0;
varsecondnum = 0;
document.write(ans);
</script>
</html>
Questions:
1. The if Statement
Use the if statement to specify a block of JavaScript code to be executed if a condition is true.
Syntax
if (condition) {
// block of code to be executed if the condition is true
}
Syntax
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}
Syntax
if (condition1) {
// block of code to be executed if condition1 is true
} else if (condition2) {
// block of code to be executed if the condition1 is false and condition2 is true
} else {
// block of code to be executed if the condition1 is false and condition2 is false
}
4.TheSwitch Statement
Use the switch statement to select one of many code blocks to be executed.
Syntax
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
JavaScript Loops
1. for loop
Loops are handy, if you want to run the same code over and over again, each time with a different value.
Syntax:-
for (initialization condition; testing condition; increment/decrement)
{
statement(s)
}
Or for objects
for (variableName in Object)
{
statement(s)
}
2. do while:
do while loop is similar to while loop with only difference that it checks for condition after executing the
statements, and therefore is an example of Exit Control Loop.
Syntax:
do
{
statements..
}while (condition);
3. While loop
A while loop is a control flow statement that allows code to be executed repeatedly based on a given
Boolean condition. The while loop can be thought of as a repeating if statement.
Syntax :
while (boolean condition)
{
loop statements...
}
Programs:
1.for loop
< /script>
2.for..in loop
// creating an Object
varlanguages = { first : "C", second : "Java",
third : "Python", fourth : "PHP",
fifth : "JavaScript"};
< /script>
varx = 21;
do
{
// The line while be printer even
// if the condition is false
document.write("Value of x:"+ x + "<br />");
x++;
} while(x < 20);
< /script>
4.while loop
varx = 1;
< /script>
5.if…else
vari = 10;
< /script>
6.switch case
vari = 9;
switch(i)
{
case0:
document.write("i is zero.");
break;
case1:
document.write("i is one.");
break;
case2:
document.write("i is two.");
break;
default:
document.write("i is greater than 2.");
}
</script>
Questions
1. Is JavaScript case sensitive? Give an example?
Creating an Array
Using an array literal is the easiest way to create a JavaScript Array.
Syntax:
var array_name = [item1, item2, ...];
Eg :-1
<html>
<body>
<script>
var i;
varemp = new Array();
emp[0] = "Arun";
emp[1] = "Varun";
emp[2] = "John";
for (i=0;i<emp.length;i++){
document.write(emp[i] + "<br>");
}
</script>
</body>
</html>
2.
<html>
<body>
<script>
varemp=["Sonoo","Vimal","Ratan"];
for (i=0;i<emp.length;i++){
document.write(emp[i] + "<br/>");
}
</script>
</body>
</html>
find() It returns the value of the first element in the given array that satisfies the specified
condition.
findIndex() It returns the index value of the first element in the given array that satisfies the
specified condition.
indexOf() It searches the specified element in the given array and returns the index of the first
match.
lastIndexOf() It searches the specified element in the given array and returns the index of the last
match.
pop() It removes and returns the last element of an array.
push() It adds one or more elements to the end of an array.
reverse() It reverses the elements of given array.
shift() It removes and returns the first element of an array.
sort() It returns the element of the given array in a sorted order.
Questions:
1. What is array?
2. How to defined array?
JavaScript functions are used to perform operations. We can call JavaScript function many times to
reuse the code.
Example
<html>
<body>
<script>
functionmsg()
{
alert("hello! this is message");
}
</script>
<input type="button" onclick="msg()" value="call function"/>
</body>
</html>
</script>
<form>
<input type="button" value="click" onclick="getcube(4)"/>
</form>
</body>
</html>
JavaScript String
The JavaScript string is an object that represents a sequence of characters.
There are 2 ways to create string in JavaScript
1. By string literal
2. By string object (using new keyword)
1) By string literal
The string literal is created using double quotes. The syntax of creating string using string literal is given
below:
var stringname="string value";
Example:
<!DOCTYPE html>
<html>
<body>
<script>
varstr="This is string literal";
document.write(str);
</script>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<body>
<script>
varstringname=new String("hello javascript string");
document.write(stringname);
</script>
</body>
</html>
lastIndexOf() It provides the position of a char value present in the given string by searching a
character from the last position.
search() It searches a specified regular expression in a given string and returns its position if a
match occurs.
match() It searches a specified regular expression in a given string and returns that regular
expression if a match occurs.
replace() It replaces a given string with the specified replacement.
substr() It is used to fetch the part of the given string on the basis of the specified starting
position and length.
substring() It is used to fetch the part of the given string on the basis of the specified index.
toLowerCase() It converts the given string into lowercase letter.
toUpperCase() It converts the given string into uppercase letter.
toString() It provides a string representing the particular object.
valueOf() It provides the primitive value of string object.
Example
<!DOCTYPE html>
<html>
<body>
<script>
varstr="javascript";
document.write(str.charAt(2));
var s1="javascript ";
var s2="concat example";
var s3=s1.concat(s2);
document.write(s3);
var s1="javascript from javatpointindexof";
var n=s1.indexOf("from");
document.write(n);
var s1="javascript from javatpointindexof";
var n=s1.lastIndexOf("java");
document.write(n);
var s1="JavaScript toLowerCase Example";
var s2=s1.toLowerCase();
document.write(s2);
var s1="JavaScript toUpperCase Example";
var s2=s1.toUpperCase();
document.write(s2);
</script>
</body>
Marks Obtained Dated Signed of
</html>
teacher
Process Product Total(50)
Related(35) Related(15)
Text input
A text field:
<input type="text" name="textfield" value="with an initial value" />
A password field:
<input type="password" name="textfield3" value="secret" />