76% found this document useful (17 votes)
25K views

Jquery Handson

The document contains 5 JavaScript functions that perform different tasks: 1) An addition function that calculates the sum of two numbers entered into form fields. 2) A login validation function that checks username and password and alerts the user. 3) A login function that redirects the user to a new page on successful login. 4) Two animation functions that toggle and change the width of elements on the page. 5) An AJAX function that loads external content into a div element.

Uploaded by

Anzal Malik
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
76% found this document useful (17 votes)
25K views

Jquery Handson

The document contains 5 JavaScript functions that perform different tasks: 1) An addition function that calculates the sum of two numbers entered into form fields. 2) A login validation function that checks username and password and alerts the user. 3) A login function that redirects the user to a new page on successful login. 4) Two animation functions that toggle and change the width of elements on the page. 5) An AJAX function that loads external content into a div element.

Uploaded by

Anzal Malik
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

addition

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

**********************************************************************

2. Login Package

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

**********************************************************************

3. Dom manipulation

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

};

function doRedirect(href) {

window.location = href;

};

**********************************************************************

4. Animation
function hover1(){
$("#item1-des").slideToggle();
};
function hover2(){
$("#item2-des").slideToggle();
};
function animate_big(){
$("#buy").animate({width:"200px"});
};
function animate_small(){
$("#buy").animate({width:"100px"});
};

**********************************************************************

5. AJAX

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

You might also like