0% found this document useful (0 votes)
176 views1 page

JavaScript Functions for User Interaction

The document contains code snippets for 5 hands-on exercises: 1) A function that adds two numbers and displays the sum. 2) A function that checks username and password and displays an alert. 3) A login function that checks credentials and redirects on success. 4) Functions for hover effects and animations. 5) A function that loads an external description file into a div.

Uploaded by

Jaithra Notla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
176 views1 page

JavaScript Functions for User Interaction

The document contains code snippets for 5 hands-on exercises: 1) A function that adds two numbers and displays the sum. 2) A function that checks username and password and displays an alert. 3) A login function that checks credentials and redirects on success. 4) Functions for hover effects and animations. 5) A function that loads an external description file into a div.

Uploaded by

Jaithra Notla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

hands on 1 -

function add() {
var a=parseInt($("#num1").val());
var b=parseInt($("#num2").val());
var sum=a+b;
$('#total').val(sum)
};

hands on 2 -
if ($("#username").val() == "admin" && $("#password").val() == "password") {
alert("You are a valid user");
} else {
alert("You are not a valid user");
}

hands on 3 -
function login() {
if ($("#username").val() == "admin" && $("#password").val() == "password") {
doRedirect("home.html")
} else {
alert("You are not a valid user");
}
};

function doRedirect(href) {
window.location.href = href;
};

hands on 4 -
function hover1(){
$("#items1-des").slideToggle();
};
function hover2(){
$("#items2-des").slideToggle();
};
function animate_big(){
$("#buy").animate({width: "200px"});
};
function animate_small(){
$("#buy").animate({width: "100px"});
};

hands on 5 -
function load_des() {
$('#item1-
des').load("https://gist.githubusercontent.com/frescoplaylab/8458dd75a120cf0cfbdf45
be813d8f03/raw/84784527d760ef1f877f0b4bb02a3a5e12e32f4c/file.html");
};

You might also like