[Go to site: main page, start]

0% found this document useful (0 votes)
8 views5 pages

Java Script

The document provides various examples of JavaScript functions and HTML elements, including basic function usage, button interactions, and form validation. It demonstrates how to create alerts, perform calculations, and validate user input in forms. Each example is presented with corresponding HTML and JavaScript code snippets.

Uploaded by

Jyothish John
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Java Script

The document provides various examples of JavaScript functions and HTML elements, including basic function usage, button interactions, and form validation. It demonstrates how to create alerts, perform calculations, and validate user input in forms. Each example is presented with corresponding HTML and JavaScript code snippets.

Uploaded by

Jyothish John
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JAVA SCRIPT

[Link]
<html>
<head>
</head>
<body>
<script>
function myFunction(a,b)
{
return a*b;
}
var x=myFunction(4,4)
alert(x);
</script>
</body>
2. FUNCTION WITHIN THE FUNCTION
<html>
<head>
</head>
<body>
<script>
function myFunction(a,b)
{
return a*b;
}
alert(myFunction(4,4));
</script>
</body>
</html>
3. INPUT TYPE = BUTTON
<!DOCTYPE html>
<html>
<body>
<input type="button" value="Click Me" />
<script>
function showMessage()
{
alert("Button was clicked!");
}
</script>
</body>
</html>
4. BUTTON TAG
<!DOCTYPE html>
<html>
<body>
<button >Click Me</button>
<script>
function showMessage()
{
alert("Button was clicked!");
}
</script>
</body>
</html>
5. DISPLAY TWO MESSAGE
<html>
<body>
<button >Click Me</button>
<button it</button>
<script>
function showMessage()
{
alert("Button was clicked!");
}
function displayDate()
{
alert( Date());
}
</script>
</body>
</html>
6. SUM ON ONCLICK
<html>
<head>
<html>
<head>
</head>
<body>
<form>
<label for="ab">First value:</label>
<input type="text" id="ab" name="ab" >
<label for="cd">Second value:</label>
<input type="text" id="cd" name="cd" >
<button Sum</button>
</form>
<script type="text/javascript">
function showSum() {
let sum = parseInt([Link]("ab").value)+
parseInt([Link]("cd").value)
alert("Sum is: " + sum);
}
</script>
</body>
</html>

7. FORM VALIDATION
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Form Validation</title>
</head>
<body>
<form validateForm()">
<input type="text" id="name" placeholder="Enter Name"><br><br>
<input type="text" id="email" placeholder="Enter Email"><br><br>
<input type="password" id="password" placeholder="Enter Password"><br><br>
<button type="submit">Submit</button>
</form>
<script>
function validateForm() {
let name = [Link]("name").value;
let email = [Link]("email").value;
let password = [Link]("password").value;
if (name === "" || email === "" || password === "") {
alert("All fields are required!");
return false;
}
return true;
}
</script>
</body>
</html>

--------------------------------------------------------------------------------------------------------------

You might also like