Unit5pdf 2023 10 24 17 21 39
Unit5pdf 2023 10 24 17 21 39
Unit-5 Javascript
Operators Description
* Multiplication
/ Division
% Modulus
+ Addition
- Subtraction
++ Increment
-- Decrement
Assignment operator
Operators Example Is Same as
= x==y x==y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
%= x%=y x=x%y
Comparison Operator
Operators Description
< Less than
<= Less than equal to
>= Greater than
== Equality
!= Inequality
=== Is equal to(checks for both types and value
Logical Operator
Operators Description Example Result
! Logical NOT !n1 Returns true if
n1 is false
&& Logical AND N1>0 && Returns true
n1<=100 only if both
conditions are
true
|| Logical OR N1==n2 | | Returns true if
n1==n3 any one
condition is true
Conditional Operator:-
Syntax: variablename = (condition) ? truepart : falsepart
Example: check =(name==“rajkot”) ? “OK” : “Not OK”
String Operator:-
Example:-var x=“Rajkot”+”MU”
Javascript Loops
• Loops can execute a block of code a number of times.
• JavaScript supports different kinds of loops:
for loop
for/in loop
for/of loop
while loop
do...while loop
for loop:-
for (statement 1; statement 2; statement 3)
{
// code block to be executed
}
for/in loop:-
• for in statement loops through the properties of an Object.
for(variablename in object)
{
statement or block to execute
}
• In each iteration, one property from object is assigned to variablename and this loop
continues till all the properties of the object are executed.
var person = {fname:"vaibhav", lname:"Patel", age:30};
for (x in person)
{
document.write(x+":"+person[x] + "<br>");
}
var subject=["WT","CD","CS","SE"];
for (x in subject)
{
document.write(subject[x]+"<br>");
}
for/of loop:-
• for of statement loops through the values of an iterable object(Array,Objects,Strings etc).
Syntax:-
for(variableName of Array_variable)
{
statement or block to execute
}
var person={firstName:'Vaibhav',lastName:'Patel',age:30}
for(key of person)
{
document.write(person[key]+"<br>");
}
while loop:-
• The while loop loops through a block of code as long as a specified condition is true.
Syntax:-
while (condition)
{
// code block to be executed
}
do..while loop:-
• The do/while loop is a variant of the while loop.
• This loop will execute the code block once, before checking if the condition is true, then it
will repeat the loop as long as the condition is true.
Syntax:-
do
{
// code block to be executed
}while (condition);
Conditional Statements
• JavaScript supports conditional statements which are used to perform different actions
based on different conditions.
• If a condition is true, you can perform one action and if the condition is false, you can
perform another action.
• There are mainly four types of conditional statements in JavaScript.
1. If Statement
2. If ... else statement
3. If ... else if.... Else statement
4. Switch statement
if statement:-
• We can use If statement if you want to check only a specific condition.
• Code is executed only if specified condition is true.
Syntax:
if(condition)
{
Code to be executed if condition is true
}
Example:-
var age=20;
if(age>18)
{
document.write("<b>Qualifies for driving</b>");
}
Note:- if is written is lowercase letters. Using uppercase letters (IF) will generate a
Javascript error!
if else statement:-
• We can use if….Else statement if you have to check two conditions and execute a
different set of codes.
Syntax:
if(condition)
{
Code to be executed if condition is true
}
else
{
Code to be executed if condition is not true
}
Example:-
var age = 15;
if(age>18)
{
document.write("<b>Qualifies for driving</b>");
}
else
{
document.write("<b>Does not qualify for driving</b>");
}
if else...if else statement:-
• We can use If….Else If….Else statement if you want to check more than two conditions.
Syntax:
if(condition1)
{
Code to be executed if condition1 is true
}
else if(condition2)
{
Code to be executed if condition2 is true
}
else
{
Code to be executed if above all is not true
}
Example:-
var book = "maths";
if(book=="history")
{
document.write("<b>History Book</b>");
}
else if(book=="maths")
{
document.write("<b>Maths Book</b>");
}
else
{
document.write("<b>Unknown Book</b>");
}
switch statement:-
• The JavaScript switch statement is used in decision making.
• The switch statement evaluates an expression and executes the corresponding body that
matches the expression's result.
Syntax:-
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
• The switch expression is evaluated once. The value of the expression is compared with
the values of each case. If there is a match, the associated block of code is executed. If
there is no match, the default code block is executed.
Example:-
let day=new Date();
switch(day.getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
document.write("Today is "+day);
• When JavaScript reaches a break keyword, it breaks out of the switch block.
• This will stop the execution inside the switch block.
• It is not necessary to break the last case in a switch block. The block breaks (ends) there
anyway.
• If you omit the break statement, the next case will be executed even if the evaluation does
not match the case.
• The default keyword specifies the code to run if there is no case match.
• If multiple cases matches a case value, the first case is selected.
User defined function
• A JavaScript function is a block of code designed to perform a particular task.
• A user-defined function saves us from rewriting the same code again and again and helps
us to make our application smaller.
• Declared functions are not executed immediately. They are "saved for later use", and will
be executed later, when they are invoked (called upon).
• A JavaScript function is defined with the function keyword, followed by a name, followed
by parentheses ().
• Function names can contain letters, digits, underscores, and dollar signs (same rules as
variables).
• Function name should be unique.
Example:-
<script>
function subjectList()
{
document.write("Web Tech<br>Compiler Design<br>Cyber Security");
}
subjectList();
</script>
function with parameter:-
• Function parameters are the names listed in the function definition.
• Function arguments are the real values passed to the function.
Example:-
function myFunction(a, b)
{
return a * b;
}
var x = myFunction(4, 3);
document.write (x);
default parameter values:-
• If a function is called with missing arguments(less than declared), the missing values are
set to undefined.
• Sometimes this is acceptable, but sometimes it is better to assign a default value to the
parameter.
Example:-
function myFunction(x=2,y=10)
{
return x + y;
}
document.write(myFunction(4));
function expression:-
• A JavaScript function can also be defined using an expression.
• A function expression can be stored in a variable.
• After a function expression has been stored in a variable, the variable can be used as a
function.
Example:-
const x=function (a,b){return a*b;};
let z=x(3,2);
document.write(z);
• The function above is actually an anonymous function (a function without a name).
• Functions stored in variables do not need function names. They are always invoked
(called) using the variable name.
• The function above ends with a semicolon because it is a part of an executable statement.
Events
• The change in the state of an object is known as an Event.
• HTML events are "things" that happen to HTML elements.
• When the page loads, it is called an event. When the user clicks a button, that click too is
an event. Other examples include events like pressing any key, closing a window, resizing
a window, etc.
• Developers can use these events to execute JavaScript code.
• Events name begin with the letters "on".
• Events can be classified into 4 categories
keyboard events
mouse events
form events
mouse events
Keyboard events:-
• Whenever a user presses any key on the Keyboard, different events are fired.
• There are three keyboard events, namely keydown, keypress, and keyup.
• One of the most common uses of keyboard events today is computer gaming. Most
browser-based games require some form of keyboard input.
onkeydown:-
• The onkeydown event occurs when the user presses a key on the keyboard.
Syntax:-<element onkeydown="myScript">
• You can write onkeydown in all HTML element except <head>, <html>, <iframe>,
<meta>, <script>, <style>, and <title>
onkeypress:-
• The onkeypress event occurs when the user presses a key on the keyboard.
Syntax:-<element onkeydown="myScript">
• You can write onkeypress in all HTML element except <head>, <html>, <iframe>,
<meta>, <script>, <style>, and <title>
Example:-
<script>
function f1(event)
{
var x=event.keyCode;
document.getElementById("demo").innerHTML=x;
}
</script>
<body>
<input type=“text” onkeypress="f1(event)"/>
<p id="demo"></p>
</body>
Note:-The onkeypress event is deprecated. It is not fired for all keys (like ALT, CTRL,
SHIFT, ESC) in all browsers. To detect if the user presses a key, always use the onkeydown
event. It works for all keys.
onkeyup:-
• The onkeyup event occurs when the user releases a key on the keyboard.
Syntax:-<element onkeyup="myScript">
• You can write onkeyup in all HTML element except <br>,<head>, <html>, <iframe>,
<meta>, <script>, <style>, and <title>
Example 1:-
<script language="javascript">
function f1()
{
var d=document.getElementById("nm1");
nm2.value=d.value;
}
</script>
Enter string<input type="text" id="nm1"onkeyup="f1()"><br>
copy string<input type="text" id="nm2">
Example 2:-
<html>
<head>
<script>
function sayHello() {
var str = document.getElementById("subject");
str.value = str.value.toLowerCase();
}
</script>
</head>
<body>
<input type = "text" onkeyup = "sayHello()" id = "subject">
</body>
</html>
Mouse events:-
onclick():-
• It occurs when the user clicks on an HTML element.
Syntax:-<element onclick="myScript">
• You can write onclick in all HTML element except <br>, <head>, <html>, <iframe>,
<meta>,<script>, <style>, and <title>
Example:-
<!DOCTYPE html>
<html>
<head>
<script>
function autoFillAddress()
{
var x=document.getElementById('addressLine1');
var y=document.getElementById('addressLine2');
var checkBox=document.getElementById('chckbox');
if(checkBox.checked==true){y.value=x.value;}
else
{y.value='';}
}
</script>
</head>
<body>
<form>
Current Address <textarea rows="7" cols="25"
id="addressLine1"></textarea><br><br>
<input type="checkbox" id="chckbox" onclick="autoFillAddress()"> Same as
permanent address<br></br>
Permanent address<textarea rows="7" cols="25" id="addressLine2"></textarea>
</form></body></html>
ondblclick():-
• It occurs when the user double-clicks on an HTML element.
Syntax:-<element ondblclick="myScript">
• You can write ondblclick in all HTML element except <br>, <head>, <html>, <iframe>,
<meta>,<script>, <style>, and <title>
<script>
function f1()
{
document.getElementById('para1').innerHTML='Marwadi University Rajkot';
}
</script>
<body>
<input type="button" ondblclick="f1()" value="Double click to see effects">
<p id="para1"></p>
</body>
onmouseover():-
• The onmouseover event in JavaScript gets activated when the mouse cursor moves over
an HTML element.
• The onmouseover event does not activate when the user clicks an element.
• For example, an onmouseover event can be used to highlight a hyperlink whenever the
user hovers the mouse over it.
onmouseenter():-
• The onmouseenter event occurs when the mouse pointer enters an element.
• The onmouseenter event is often used together with the onmouseleave event, which
occurs when the mouse pointer leaves an element.
onmousemove():-
• It occurs when the pointer moves over an element.
Note:-difference between mouseover(),mouseenter() and mousemove()
mouseover:-The onmouseover event triggers when the mouse pointer enters an element or
any one of its child elements.
mouseenter:-The onmouseenter event is triggered only when the mouse pointer hits the
element.
mousemove:-The onmousemove event is triggered each time the mouse pointer is moved
when it is over an element.
<!DOCTYPE html>
<html>
<style>
div {
width: 150px;
height: 100px;
border: 1px solid black;
margin: 10px;
padding: 5px;
text-align: center;
background-color: lightgray;
}
h3
{
background-color: rgb(228, 15, 200);
}
</style>
<body>
<h2>onmousemove</h2>
<div onmousemove="myMoveFunction()">
<h3 id="demo1">Mouse over me!</h3>
</div>
<h2>onmouseenter</h2>
<div onmouseenter="myEnterFunction()">
<h3 id="demo2">Mouse over me!</h3>
</div>
<h2>onmouseover</h2>
<div onmouseover="myOverFunction()">
<h3 id="demo3">Mouse over me!</h3>
</div>
<script>
let x = 0;
let y = 0;
let z = 0;
function myMoveFunction() {
document.getElementById("demo1").innerHTML = z+=1;
}
function myEnterFunction() {
document.getElementById("demo2").innerHTML = x+=1;
}
function myOverFunction() {
document.getElementById("demo3").innerHTML = y+=1;
}
</script>
</body>
</html>
onmouseout():-
• The onmouseout event occurs when the mouse pointer moves out of an element.
• The onmouseout event is often used together with the onmouseover event, which occurs
when the pointer is moved over an element.
onmouseleave():-
• It occurs when the mouse pointer leaves an element.
• The onmouseleave event is often used together with the onmouseenter event, which
occurs when the mouse pointer enters an element.
<!DOCTYPE html>
<html>
<head>
<style>
div
{
width: 100px;
height: 100px;
border: 1px solid black;
margin: 10px;
float: left;
padding: 30px;
text-align: center;
background-color: lightgray;
}
p
{
background-color: white;
}
</style>
</head>
<body>
<div onmousemove="myMoveFunction()">
<p>onmousemove: <br> <span id="demo">Mouse over and leave me!</span></p>
</div>
<div onmouseleave="myLeaveFunction()">
<p>onmouseleave: <br> <span id="demo2">Mouse over and leave me!</span></p>
</div>
<div onmouseout="myOutFunction()">
<p>onmouseout: <br> <span id="demo3">Mouse over and leave me!</span></p>
</div>
<script>
var x = 0,y = 0,z = 0;
function myMoveFunction() {
document.getElementById("demo").innerHTML = z+=1;
}
function myLeaveFunction() {
document.getElementById("demo2").innerHTML = x+=1;
}
function myOutFunction() {
document.getElementById("demo3").innerHTML = y+=1;
}
</script>
</body>
</html>
Note:-The mouseleave event only occurs when the mouse pointer is moved out of the div
element.The onmouseout event occurs when the mouse pointer is moved out of the div
element, and when it leaves its child elements (p and span).
onmousedown():-The onmousedown event occurs when a user presses a mouse button over
an HTML element.
onmouseup():-The onmouseup event occurs when a mouse button is released over an
element.
<body>
<p id="para1" onmouseup="f2()" onmousedown="f1()">Lorem ipsum dolor </p>
<script>
function f1()
{
document.getElementById('para1').style.color='red';
}
function f2()
{
document.getElementById('para1').style.color='green';
}
</script>
</body>
Form events:-
onchange():-
• The onchange event attribute works when the value of the element changes and select the
new value from the List.
• You can write onchange with following HTML Tags:<input type="checkbox">, <input
type="file">, <input type="password">, <input type="radio">, <input type="range">,
<input type="search">, <input type="text">, <select> and <textarea>
Example:-
<script>
function test1()
{
var d=document.getElementById("opt").value;
document.getElementById("a1").innerHTML=d;
}
</script>
<body>
<form>
<select id="opt" onchange="test1()">
<option value="">Select course</option>
<option>Engineering</option>
<option>MCA</option>
<option>MBA</option>
</select>
<h1>select stream is=<b id="a1"></h1>
</form>
</body>
onfocus():-
• The onfocus attribute fires the moment that the element gets focus.
• onfocus is most often used with <input>, <select>, and <a>.
onblur():-
• The onblur attribute fires the moment that the element loses focus.
• onblur is most often used with form validation code (e.g. when the user leaves a form
field).
Example:-
<form>
<input type="text" id="hh1" placeholder="Enter Your FirstName" onfocus="f1()"
onblur="f2()"><span id="hh2"></span><br><br>
<input type="text">
</form>
<script>
function f1()
{
document.getElementById('hh1').style.background='lightgrey';
}
function f2()
{
var x=document.getElementById('hh1').value;
var firstNameCheck=/^[a-z]+$/;
if(firstNameCheck.test(x))
{
document.getElementById('hh2').innerHTML='';
}
else
{
document.getElementById('hh2').innerHTML='Invalid';
}
}
</script>
</body>
onsubmit():-
• The onsubmit attribute fires when a form is submitted.
• You can write onsubmit event with form attribute only.
onreset():-
• The onreset attribute fires when a form is reset.
• You can write onreset event with form attribute only.
<form onreset="f2()" onsubmit="f1()">
Enter name: <input type="text"><br><br>
<input type="submit"> <input type="reset">
</form>
<script>
function f1()
{
alert("The form was submitted");
}
function f2() {
alert("The form was reset");
}
</script>
</body>
windows events
onload():-
• The onload attribute fires when an object has been loaded.
• onload is most often used within the <body> element to execute a script once a web page
has completely loaded all content (including images, script files, CSS files, etc.).
However, it can be used on other elements as well.
• The onload attribute can be used to check the visitor's browser type and browser version,
and load the proper version of the web page based on the information.
• You can write onload event with following HTML tags:<body>,<frame>, <frameset>,
<iframe>, <img>, <input type="image">, <link>, <script> and <style>
Example:-
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
alert("Page is loaded");
}
</script>
</head>
<body onload="myFunction()">
<h1>Marwadi University Rajkot</h1>
</body>
</html>
onunload():-
• The onunload attribute fires once a page has unloaded (or the browser window has been
closed).
• onunload occurs when the user navigates away from the page (by clicking on a link,
submitting a form, closing the browser window, etc.)
• Due to different browser settings, this event may not always work as expected.
Example:-
<!DOCTYPE html>
<html>
<body onunload="myFunction()">
<script>
function myFunction() {
alert("Thank you for visiting W3Schools!");
}</script>
onresize():-
• The onresize attribute fires when the browser window is resized.
• You can write onresize event with body tag only.
Example:-
<body onresize="myFunction()">
<script>
function myFunction() {
alert("You have changed the size of the browser window!");
}
</script>
</body>
onerror():-
• The onerror attribute fires when an error occurs while loading an external file (e.g. a
document or an image).
• You can write onerror event with following HTML tags:<img>, <input type="image">,
<link>, and <script>
Example:-
<body>
<img src="1.jpg" onerror="myFunction()">
<script>
function myFunction() {
alert("The image could not be loaded.");
}
</script>
</body>
DOM
• It is an API for manipulating HTML elements.(add,remove and modify elements)
• When a web page is loaded, the browser creates a Document Object Model of the page.
• In this DOM tree, the document is the root node or object.
• With object model
Change all the HTML elements in page
change all the HTML attributes in page
change all the CSS styles in the page
remove existing HTML elements and attributes
add new HTML elements and attributes
react to all existing HTML events in the page
• In the DOM, all HTML elements are defined as objects.so it will have both property and method.
• If you want to access any HTML element in an HTML page, you always start with accessing the
document object.
DOM Methods
getElementsByClassName():-
• It is used for selecting or getting the elements through their class name value.
• This DOM method returns an array-like object that consists of all the elements having the
specified classname.
• On calling the getElementsByClassName() method on any particular element, it will
search the whole document and will return only those elements which match the specified
or given class name.
Example:-
<body>
<ul>
<li class="subject">Web Technology</li>
<li>Compiler Design</li>
<li class="subject">Cyber Security</li>
</ul>
<script>
var x=document.getElementsByClassName('subject');
for(var i=0;i<x.length;i++)
{
x[i].style.color='red';
}
</script>
</body>
getElementsByTagName():-It returns the collection of all elements in the document with
given tag name.
Example:-
<body>
<h2>Javascript</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sunt, ducimus?</p>
<h2>PHP</h2>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.</p>
<script>
var x=document.getElementsByTagName('h2');
for(var i=0;i<x.length;i++)
{
x[i].style.color='red';
}
</script>
</body>
getElementsByName():-
• It returns a collection of elements with specified name.
• This collection is called node list and each element of the node list can be visited with the
help of the index.
Example:-
<body>
<form>
<input type="radio" name="gender" value="male">Male
<input type="radio" name="gender" value="male">Female
<span id="hh1"></span><br><br>
<input type="button" onclick="f1()" value="CLICK HERE">
</form>
<script>
function f1()
{
var gen=document.getElementsByName('gender');
if(gen[0].checked==true||gen[1].checked==true)
{
document.getElementById('hh1').innerHTML='';
}
else
{
document.getElementById('hh1').innerHTML='select your gender';
}
}
</script>
</body>
getElementById():-
• It returns the element of specified id.
• It returns null if the element does not exist.
• It is one of the most common methods in the HTML DOM. It is used almost every time
you want to read or edit an HTML element.
Example:-
<script type="text/javascript">
function getcube(){
var number=document.getElementById("number").value;
alert(number*number*number);
}
</script>
<form>
Enter No:<input type="text" id="number" name="number"/><br/>
<input type="button" value="cube" onclick="getcube()"/>
</form>
write():-
• It is a function that is used to display some strings in the output of HTML web pages
(Browser window).
Syntax:-document.writeln(exp1,exp2,...,expn)
• By using document.write() method, we can pass an expression called as 'single argument'
or can pass multiple values separated by commas "," known as 'multiple arguments'.
• These values can be displayed in sequential order as they are written in the method of
document.write in javascript.
Array
• JavaScript array is a single variable that is used to store different elements.
• It is often used when we want to store a list of elements and access them by a single
variable.
Create an Array
• You can create an array using two ways:
1.Using an array literal:-The easiest way to create an array is by using an array literal [].
Example:-const sem6=["WT","CD","CS","SE"];
2.Using the new keyword
• You can also create an array using JavaScript's new keyword.
const sem6=new Array("WT","CD","CS","SE");
• It is recommended to use array literal to create an array.
• Here, sem6 is an array. The array is storing 4 values.
Access Elements of an Array
• You can access elements of an array using indices (0, 1, 2 …). For example,
const sem6=["WT","CD","CS","SE"];
console.log(sem6[0]);//WT
console.log(sem6[2]);//CS
Looping Array Elements
• One way to loop through an array, is using a for loop:
const sem6=["WT","CD","CS","SE"];
for(i=0;i<sem6.length;i++)
{
document.write(sem6[i]+"<br>");
}
Array Methods
length:-
• The length property return length of an array.
const sem6=["WT","CD","CS","SE"];
document.write("arr.length is : " +sem6.length);
push():-
• The push() method adds one or more elements to the end of an array.
var a=["vaibhav","harsh"];
a.push("jill","Divyesh");
document.write(a);
unshift():-
• It is used to add one or more elements to the beginning of the given array.
• This method accepts a single parameter. This parameter element is to be added at the
beginning of the array.
const sem6=["WT","CD","CS","SE"];
sem6.unshift("Python","Computer Network");
document.write(sem6);
pop():-
• It is used to remove the last element of the array and also returns the removed element.
• This method does not accept any parameter.
• If the array is empty, then this function returns undefined.
const sem6=["WT","CD","CS","SE"];
sem6.pop();
document.write(sem6);
shift():-
• It removes the first element of the array.
• This method does not accept any parameter.
• If the array is empty then this function returns undefined.
const sem6=["WT","CD","CS","SE"];
sem6.shift();
document.write(sem6);
concat():-
• The concat() method is used to merge two or more arrays together.
var a=["vaibhav","raj"];
var b=["jill","divyesh"];
var c=a.concat(b);
document.write(c);
sort():-
• The sort() method will sort the elements alphabetically.
var arr=["AngularJS","Nodejs","JQuery","Bootstrap"]
arr.sort();
document.writeln(arr); //AngularJS,Bootstrap,JQuery,Nodejs
var priceList = [1000, 50, 2, 7, 14];
priceList.sort();
document.writeln(priceList);
reverse():-
• The reverse() method returns the array in reverse order.
• The reverse() method does not take any parameters.
let numbers = [1, 2, 3, 4, 5];
numbers.reverse();
document.write(numbers);
Window Scrolling
scrollTo():-
• The scrollTo() method scrolls the document to specified coordinates.
• For the scrollTo() method to work, the document must be larger than the screen, and the
scrollbar must be visible.
Syntax:-window.scrollTo(x,y) OR scrollTo(x,y)
Parameters:-
x:-Required.The coordinate to scroll to (horizontally), in pixels.
y:-Required.The coordinate to scroll to (vertically), in pixels.
scroll():-
• The Window scroll() method scrolls the window to a particular place in the document.
This method is different form scrollTo() method as it takes different parameters like
scrolling behavior, etc using ScrolltoOptions Dictionary.
Syntax:-window.scroll(x-coord, y-coord) OR window.scroll(top,left,behavior)
Parameters:-
top:-Specifies the number of pixels along the Y axis to scroll the window or element.
left:-Specifies the number of pixels along the X axis to scroll the window or element.
behavior:-Determines whether scrolling is instant or animates smoothly. This option is a
string which must take one of the following values:
smooth:-scrolling should animate smoothly
instant:-scrolling should happen instantly in a single jump
<body>
<script language="JavaScript">
function function1(){
window.scrollTo(200,200);
}
function function2(){
window.scroll(400,400);
}
</script>
<input type="button" value="Scroll to (200,200)" onClick="function1();">
<input type="button" value="Scroll(400,400)" onClick="function2();">
<div style="height:1000;width:1500;background-color:blue;"></div>
</body>
Thank You