Showing posts with label JavaScript Program. Show all posts
Showing posts with label JavaScript Program. Show all posts

Sunday, 12 January 2025

Write a program to Password length 6 char using JavaScript

<-- HyperText Markup Language-->

 <html>

<--to store metadata about a web page-->

<head>

<--to define the title of a document.-->


    <title>Form Validation</title>

    <style>

        body {

            font-family: Arial, sans-serif;

            margin: 0;

            padding: 0;

            background-color: #f4f4f4;

            display: flex;

            justify-content: center;

            align-items: center;

            height: 100vh;

        }

        .form-container {

            background-color: #fff;

            padding: 20px;

            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);

            border-radius: 8px;

            width: 300px;

        }

        h2 {

            text-align: center;

        }

        label {

            display: block;

            margin-bottom: 5px;

        }

        input[type="text"],

        input[type="email"],

        input[type="password"] {

            width: 100%;

            padding: 8px;

            margin-bottom: 10px;

            border: 1px solid #ccc;

            border-radius: 4px;

        }

        input[type="submit"] {

            width: 100%;

            padding: 10px;

            background-color: #4CAF50;

            color: white;

            border: none;

            border-radius: 4px;

            cursor: pointer;

        }

        input[type="submit"]:hover {

            background-color: #45a049;

        }

        .error {

            color: red;

            font-size: 0.9em;

        }

    </style>

</head>

<body>


    <div class="form-container">

        <h2>Registration Form</h2>

        <form id="registrationForm" onsubmit="return validateForm()">

            <!-- Name Field -->

            <label for="name">Full Name:</label>

            <input type="text" id="name" name="name">

            <span id="nameError" class="error"></span>


            <!-- Email Field -->

            <label for="email">Email:</label>

            <input type="email" id="email" name="email">

            <span id="emailError" class="error"></span>


            <!-- Password Field -->

            <label for="password">Password:</label>

            <input type="password" id="password" name="password">

            <span id="passwordError" class="error"></span>


            <!-- Confirm Password Field -->

            <label for="confirmPassword">Confirm Password:</label>

            <input type="password" id="confirmPassword" name="confirmPassword">

            <span id="confirmPasswordError" class="error"></span>


            <!-- Submit Button -->

            <input type="submit" value="Submit">

        </form>

    </div>


    <script>

        function validateForm() {

            // Clear previous error messages

            document.getElementById('nameError').innerText = '';

            document.getElementById('emailError').innerText = '';

            document.getElementById('passwordError').innerText = '';

            document.getElementById('confirmPasswordError').innerText = '';


            let isValid = true;


            // Get form values

            let name = document.getElementById('name').value;

            let email = document.getElementById('email').value;

            let password = document.getElementById('password').value;

            let confirmPassword = document.getElementById('confirmPassword').value;


            // Name Validation: check if empty

            if (name === '') {

                document.getElementById('nameError').innerText = 'Name is required.';

                isValid = false;

            }


            // Email Validation: check if empty and valid format

            let emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;

            if (email === '') {

                document.getElementById('emailError').innerText = 'Email is required.';

                isValid = false;

            } else if (!emailPattern.test(email)) {

                document.getElementById('emailError').innerText = 'Please enter a valid email address.';

                isValid = false;

            }


            // Password Validation: check if empty and length is at least 6 characters

            if (password === '') {

                document.getElementById('passwordError').innerText = 'Password is required.';

                isValid = false;

            } else if (password.length < 6) {

                document.getElementById('passwordError').innerText = 'Password must be at least 6 characters long.';

                isValid = false;

            }


            // Confirm Password Validation: check if it matches the password

            if (confirmPassword === '') {

                document.getElementById('confirmPasswordError').innerText = 'Please confirm your password.';

                isValid = false;

            } else if (confirmPassword !== password) {

                document.getElementById('confirmPasswordError').innerText = 'Passwords do not match.';

                isValid = false;

            }


            return isValid; // Return false to prevent form submission if validation fails

        }

    </script>


</body>

</html>



Write a program to Check Password Confirmation using JavaScript

 <html>

<head>

    <style>

        .PC {

            font-size: 40px;

            color: green;

            font-weight: bold;

            text-align: center;

        }

        .cs {

            font-size: 17px;

            text-align: center;

            margin-bottom: 20px;

        }

    </style>

</head>

<body>

    <div class="PC">Password Confirmation</div>

    <div class="cs">computer science </div>

    <form onSubmit="return checkPassword(this)">

        <table border=1 align="center">

            <tr>

                <!-- Enter Username -->

                <td>Username:</td>

                <td><input type=text name=name size=25></td>

            </tr>

            <tr>

                <!-- Enter Password. -->

                <td>Password:</td>

                <td><input type=password name=password1 size=25></td>

            </tr>

            <tr>

                <!-- To Confirm Password. -->

                <td>Confirm Password:</td>

                <td><input type=password name=password2 size=25></td>

            </tr>

            <tr>

                <td colspan=2 align=right>

                    <input type=submit value="Submit">

                </td>

            </tr>

        </table>

    </form>

    <script>

        // Function to check Whether both passwords

        // is same or not.

        function checkPassword(form) {

            password1 = form.password1.value;

            password2 = form.password2.value;

 

            // If password not entered

            if (password1 == '')

                alert("Please enter Password");

            // If confirm password not entered

            else if (password2 == '')

                alert("Please enter confirm password");

            // If Not same return False.    

            else if (password1 != password2) {

                alert("\nPassword did not match: Please try again...")

                return false;

            }

            // If same return True.

            else {

                alert("Password Match: Welcome to Our Page.....")

                return true;

            }

        }

    </script>

</body>

</html>


Thursday, 9 January 2025

Write a program Event Handling

 

<html>

<body>

<h1>JavaScript HTML Events</h1>

<h2>The onclick Attribute</h2>


<button onclick="document.getElementById('demo').innerHTML=Date()">The time is?</button>


<p id="demo"></p>


</body>

</html>









Sunday, 29 December 2024

Write a program Validation using Javascript

 <html>

<head>

<script>

function myFunction() {

  // Get the value of the input field with id="numb"

  let x = document.getElementById("numb").value;

  // If x is Not a Number or less than one or greater than 10

  let text;

  if (isNaN(x) || x < 1 || x > 10) {

    text = "Input not valid";

  } else {

    text = "Input OK";

  }

  document.getElementById("demo").innerHTML = text;

}

</script>

</head>

<body>

<h2>JavaScript Validation</h2>

<p>Please input a number between 1 and 10:</p>

<input id="numb">

<button type="button" onclick="myFunction()">Submit</button>

<p id="demo"></p>

</body>

</html> 
















Thursday, 26 December 2024

Write a program Count Vowels using Javascript

<html>

<head>

<title>find number of vowels in a string in JavaScript</title>

<script type="text/javascript">

function GetVowels() {

var str = document.getElementById('txtname').value;

var count = 0, total_vowels="";

for (var i = 0; i < str.length; i++) {

if (str.charAt(i).match(/[a-zA-Z]/) != null) {

// findVowels

if (str.charAt(i).match(/[aeiouAEIOU]/))

{

total_vowels = total_vowels + str.charAt(i);

count++;

}

}

}

document.getElementById('vowels').value = total_vowels;

document.getElementById('vcount').value = count;

}

</script>

</head>

<body>

<div >

<table border="1px" cellspacing="0" width="30%" style="background-color: #FF6600; color:White">

<tr><td colspan="2" align="center"><b>Get Vowels from String</b></td></tr>

<tr>

<td>Enter Text :</td>

<td><input type='text' id='txtname' /></td>

</tr>

<tr>

<td>Vowels Count :</td>

<td><input type='text' readonly="readonly" id='vcount'/></td>

</tr>

<tr>

<td>Total Vowels :</td>

<td><input type='text' readonly="readonly" id='vowels' /></td>

</tr>

<tr>

<td></td>

<td><input type='button' value='Get Vowels Count' onclick="javascript:GetVowels();" /></td>

</tr>

</table>

</div>

</body>

</html>








Wednesday, 18 December 2024

Write Program To Subtract Two number using javascript

 <!doctype html>

<html>

<head>

<script>

function Sub()

{

  var numOne, numTwo, sum;

  numOne = parseInt(document.getElementById("first").value);

  numTwo = parseInt(document.getElementById("second").value);

  sum = numOne - numTwo;

  document.getElementById("answer").value = sum;

}

</script>

</head>

<body>

<p>Enter the First Number: <input id="first"></p>

<p>Enter the Second Number: <input id="second"></p>

<button onclick="Sub()">Sub</button>

<p>Sum = <input id="answer"></p>

</body>

</html>















Write Program To Add Two number using javascript

 


<!doctype html>

<html>

<head>

<script>

function add()

{

  var numOne, numTwo, sum;

  numOne = parseInt(document.getElementById("first").value);

  numTwo = parseInt(document.getElementById("second").value);

  sum = numOne + numTwo;

  document.getElementById("answer").value = sum;

}

</script>

</head>

<body>


<p>Enter the First Number: <input id="first"></p>

<p>Enter the Second Number: <input id="second"></p>

<button onclick="add()">Add</button>

<p>Sum = <input id="answer"></p>


</body>

</html>

Monday, 16 December 2024

Write a program to Confirm Dilog Box

 


<html>

<body>

<h2>JavaScript Confirm Box</h2>


<button onclick="myFunction()">Click Me</button>

<p id="demo"></p>

<script>

function myFunction() {

  var txt;

  if (confirm("Press a button!")) {

    txt = "You pressed OK!";

  } else {

    txt = "You pressed Cancel!";

  }

  document.getElementById("demo").innerHTML = txt;

}

</script>


</body>

</html>


Write a program to Prompt Dilog Box using html JavaScript

 <html>

<body>


<h2>JavaScript Prompt</h2>


<button onclick="myFunction()">Click Me</button>


<p id="demo"></p>


<script>

function myFunction() {

  let text;

  let person = prompt("Please enter your name:", "Savera");

  if (person == null || person == "") {

    text = "User cancelled the prompt.";

  } else {

    text = "Hello " + person + "! How are you today?";

  }

  document.getElementById("demo").innerHTML = text;

}

</script>


</body>

</html>


Write a program to Confirm Dilog Box using html

 <html>

<body>

<h2>JavaScript Confirm Box</h2>

<button onclick="myFunction()">Click Me</button>

<p id="demo"></p>

<script>

function myFunction() {

  var txt;

  if (confirm("Press a button!")) {

    txt = "You pressed OK!";

  } else {

    txt = "You pressed Cancel!";

  }

  document.getElementById("demo").innerHTML = txt;

}

</script>

</body>

</html>


Write a program To Alert Box using html

 <html>

<body>

<h2>JavaScript Alert</h2>

<button onclick="myFunction()">CLick Me</button>

<script>

function myFunction() {

 alert("I am an alert box!");

}

</script>

</body>

</html>

Write a program to alert Dilox box in Javascript

 <HTML>

<HEAD>

<TITLE>ALERT BOX EXAMPLE</TITLE>

</HEAD>

<BODY>

<SCRIPT Language="JavaScript">

alert("Welcome to Our Website!!!");

document.write('<IMG SRC=""/>');

</SCRIPT>

</BODY>

</HTML>






Write a program to Prompt Dilog Box in Javascript

 <HTML>

<HEAD>

<TITLE>PROMPT BOX EXAMPLE</TITLE>

</HEAD>

<BODY>

<SCRIPT Language="JavaScript">

document.write("<h1>Greetings</h1>");

document.write(prompt("Enter Your Name: ", "Name"));

document.write(" Welcome to Our Site!</h1>");

</SCRIPT>

</BODY>

</HTML>



Friday, 20 September 2024

Write a program to check String is Equal or not using Javascript

 <!DOCTYPE html>

<html>

<head>

<title>equal</title>

<script type="text/javascript">

var i;

i=0;

for (var i = 1; i < 4; i++)

{

var s1="Savera";

var s2=prompt("enter the string")

if (s1==s2)

{

alert("string is equal")

}

else

{

alert("string is not equal")

}

}

</script>

</head>

<body>

</body>

</html>

Write a program to Check Number Even or Odd using Javascript

 <!DOCTYPE html>

<html>

<head>

<title>Even or odd</title>

</head>

<body>

<script type="text/javascript">

var n=prompt("Enter the number even or odd");

n=parseInt(n);

if (isNaN(n))

{

alert("Enter the number");

}

else if(n==0)

{

alert("The number is zero");

}

else if (n%2) 

{

alert("The number is odd");

}

else

{

alert("The number is enen");

}

</script>

</body>

</html>

Write a program to Factorial Number Using Javascript

 <!DOCTYPE html>

<html>

<head>

<title>factorial</title>

<script type="text/javascript">

var a=prompt("Enter value");

var b=a;

var c=a;

for (var i = 2; i < a; i++)

{

c=c-1;

b=b*c

}

alert(b)

</script>

</head>

</html>

Wite a program to Fiboncy Number Using Javascript

 <!DOCTYPE html>

<html>

<head>

<title>fiboncci</title>

</head>

<body>

<script type="text/javascript">

var a=0,b=1,c,count;

n=window.prompt("Enter the value generate fibonci");

var num=parseInt(n);

document.writeln("<h1>Fiboncci sries for"+num+"terms</h1>");

count=1;

document.writeln(+a+"<br>"+b);

while(count<=num-2)

{

c=a+b;

document.write("<br>"+c+"<br>");

a=b;

b=c;

     ++count;

}

</script>

</body>

</html>

************************************Output************************************

Fiboncci sries for5terms

0
1
1

2

3

Thursday, 19 September 2024

Write a program to Armstrong Number using JavaScript

 <!DOCTYPE html>

<html>
<head>
	<title>Armstrong number</title>
</head>
<body>
<script type="text/javascript">
	var b,z,c=0;
	var a=prompt("Enter a number");
    z=a;
    while(z>0)
   {
   	b=z%10;
   	c=c+(b*b*b);
   	z=parseInt(z/10);
   }
   if (a==c)
    alert("number is a Armstrong");
else
	alert("number is not Armstrong");
</script>
</body>
</html>

Tuesday, 10 September 2024

Write a program to Adition Two number using javascript

<!doctype html>

<html>

<head>

<title>Add Two Numbers</title>

<script>

  var numOne = 10;

  var numTwo = 20;

  var sum = numOne + numTwo;

  document.write("Sum = " + sum);

</script>

</head>

<body>

</body>

</html>

Friday, 23 August 2024

Write a Program Leaf Year or Not in Javascript

 <!DOCTYPE html>

<html>

<head>

<title>leap year</title>

<script type="text/javascript">

     var b,c;

     var a=prompt("Enter year");

     b=a%4;

     c=a%400;

     if(b==0||c==0)

     {

        alert("Given number is leaf");

     }   

     else

     {

        alert("Given number is Not leaf")

     }

    </script>

</head>

<body>

</body>

</html>




























Data Science using Spreadsheet Software Assignment 3

Printing Workbooks select the cells you want to print and then set that area as the print area   Steps to set a print area: Select the cells...