WEB TECHNOLOGY

  1. Write a JavaScript function that checks password and retyped password of two different password fields are same or not.

<html>

<head>

<title>web</title>

<script type=”text/javascript”>

function validate(){

var mypwd=document.myform.pwd.value;

var myrpwd=document.myform.rpwd.value;

if(mypwd !=myrpwd) {

alert(“password doesn’t match”);

return false;

}

else{

alert(“okay”);

return true;

}

}

</script>

</head>

<body>

<form name=”myform”>

<fieldset>

<legend>Confirm Password</legend>

<label> Password: <input type=”password” name=”pwd”></label>

<label> Retype-Password: <input type=”password” name=”rpwd”></label>

<button onclick=”return validate();”>Confirm</button>

</fieldset>

</form>

</body>

</html>

  • Write a JavaScript code to check if a number given by user is prime or not.

<html>

<head>

<title>Prime check</title>

<script type=”text/Javascript”>

var a=prompt (“Enter a num: “);

var i, flag1=0; for(i=2; i<a/2;i++)

{

if(i==0) {

flag1=1;

break;

}

}

if(flag1==0) {

document.write (a+” is a a prime number”);

}

else {

document.write (a+” is not a prime number”); 0}

</script>

</head>

<body>

</body>

</html>

3

Capture.JPG

<html>

<head>

<style>

table

{

border:1px solid black;

}

</style>

</head>

<body>

<table border=”width:50%”>

<tr>

<th colspan=”2″>Subject</th>

<th> John Doe</th>

<th>Mirim Luther</th>

</tr>

<td rowspan=”2″><b>Biology</b></td>

<td><b>Practical</b></td>

<td> A</td>

<td>A</td>

</tr>

<tr>

<td><b> Theory</b></td>

<td>A+</td>

<td> A</td>

</tr>

<tr>

<td rowspan=”2″><b>Chemistry</b></td>

<td><b>Practical</b></td>

<td>B</td>

<td>C</td>

</tr>

<tr>

<td><b>Theory</b></td>

<td>A</td>

<td>C+</td>

</tr>

<tr>

<td rowspan=”2″><b>Physics</b></td>

<td><b>Practicals</b></td>

<td>A </td>

<td>A</td>

</tr>

<tr>

<td><b> Theory</b></td>

<td>A-</td>

<td>A-</td>

</tr>

</table>

</body>

</html>

.Capture.JPG

<html>

       <head>

                       <title>Divs</title>

                       <style type=”text/css”>

                                       .main{border:2px solid black; height:500px;width:1000px;}

                                       .fr{height:100px;width:1000px;border-bottom:2px solid black;}

                                       .fr1{height:100px;width:800px;border-right:2px solid black;float:left;}

                                       .fr2{height:100px;width:200px;float:right;}

                                       .sr{height:300px;width:1000px;border-bottom:2px solid black;}

                                       .sr1{height:300px;width:200px;border-right:2px solid black;float:left;}

                                       .sr2{height:300px;width:800px;float:right;}

                                       .tr{height:100px;width:1000px;}

                       </style>

       </head>

       <body>

                       <div class=”main”>

                                       <div class=”fr”>

                                                       <div class=”fr1″></div>

                                                       <div class=”fr2″></div>

                                       </div>

                                       <div class=”sr”>

                                                       <div class=”sr1″></div>

                                                       <div class=”sr2″></div>

                                       </div>

                                       <div class=”tr”></div>

                       </div>

       </body>

</html>

222.JPG

<html>

       <head>

                       <title>String 4</title>

       </head>

       <body>

       <script type=”text/Javascript”>                

str1=new String(“BIM Study Notes”);

var a1=str1.length;

str2=new String(“BIM Study Notes”);

 var a2=str2.length;

       var i;

       var count=0;

       for(i=0;i<=a1;i++)

                       {

                                       if(str1.charAt(i)!=str2.charAt(i))

                       {

                                                       count++;

                                                                       break;

                                                       }

                       }

                       if(count==0)

                       {

document.write(“<br>Uppercase is: “+str1.toUpperCase());

       }

else document.write(“<br>They are not equal”);

                       </script>

       </body>

</html>

Why do we need to validate form values?

Write JavaScript to validate a form with input name (can not be empty), and contact (must be 10 digit)

<html>

<head>

<script>

function validateForm() {

  var x = document.forms[“myForm”][“fname”].value;

  var y = document.forms[“myForm”][“Cname”].value;

  if (x == “”)

  {

    alert(“Name must be filled out”);

    return false;

  }

  else if (y.length!=10)

  {

    alert(“Contact must be 10 digit”);

    return false;

  }

}

</script>

</head>

<body>

<form name=”myForm” action=”/action_page.php” onsubmit=”return validateForm()” method=”post”>

        Name: <input type=”text” name=”fname”>

  Contact: <input type=”text” name=”Cname”>

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

</form>

</body>

</html>

  Write a java Script  program to reverse the given input integer input to output.

<!doctype html>

<html>

<head>

<script>

function palin()

{

var a,no,b,temp=0;

no=Number(document.getElementById(“no_input”).value);

b=no;

while(no>0)

{

a=no%10;

no=parseInt(no/10);

temp=temp*10+a;

}

alert(temp);

}

</script>

</head>

<body>

Enter any Number: <input id=”no_input”>

<button onclick=”palin()”>Check</button></br></br>

</body>

</html>

aaadasdas.JPG

<!DOCTYPE html>

<html>

<head>

       <title></title>

</head>

<body>

       <script type=”text/javascript”>

                       var fruitArray=[‘Apple’,’Orange’,’Mango’];

                       fruitArray.unshift(‘Strawberry’,’Bananan’,’Guava’);

                       fruitArray.pop();

                       fruitArray.pop();

                       var stringArray=fruitArray.toString();

                       alert(stringArray);

       </script>

</body>

</html>

  Write a html form for sending email with a form item like send to , cc, subject, message & send button included.

<!DOCTYPE html>

<html>

<head>

</head>

<body>

<form method=”post”>

  Send to: <input type=”email” name=”fname”>

  <br>

  cc: <input type=”email” name=”cc”>

  <br>

  Subject: <input type=”text” name=”sub”>

  <br>

  Message: <textarea name=”message” rows=”10″ cols=”30″></textarea>

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

</form>

</body>

</html>

sdasdadas.JPG

<html>

<head>

<title>this is title</title>

<style>

table, th, td{

border: 1px solid black;

border-collapse: collapse;

}

th, td{

padding: 10px;

}

</style>

 </head>

<body>

<h1>Students Details</h1>

<table width=”50%” height=”30%”

<tr>

<th rowspan=”2″>Name</th>

 <th colspan=”3″>Subjects</th>

 <th rowspan=”2″>total</th>

</tr>

<tr>

<th>computer</th>

<th>account</th>

<th>mathematics</th>

</tr>

<tr>

<td>Ram</td>

 <td>20</td>

<th>computer</th>

<th>account</th>

<th>mathematics</th>

 </tr>

<tr>

<td>Ram</td>

 <td>20</td>

 <td>30</td>

<td>40</td>

<td>90</td>

</tr>

<tr>

<td>Shyam</td>

 <td>30</td>

<td>20</td>

<td>50</td>

<td>100</td>

</tr>

<tr>

<td>Hari</td>

<td>10</tds

<td>10</td>

<td>10</td>

<td> 30</td>

</table>

 </body>

</html>

n the case of an Armstrong number of 3 digits, the sum of cubes of each digit is equal to the number itself. For example, 153 is an Armstrong number because

153 = 1*1*1 + 5*5*5 + 3*3*3

// program to check an Armstrong number of three digits
 
let sum = 0;
const number = prompt('Enter a three-digit positive integer: ');
 
// create a temporary variable
let temp = number;
while (temp > 0) {
    // finding the one's digit
    let remainder = temp % 10;
 
    sum += remainder * remainder * remainder;
 
    // removing last digit from the number
    temp = parseInt(temp / 10); // convert float into integer
}
// check the condition
if (sum == number) {
    console.log(`${number} is an Armstrong number`);
}
else {
    console.log(`${number} is not an Armstrong number.`);
}

Check Number Type with if…else if…else

// program that checks if the number is positive, negative or zero

// input from the user

const number = parseInt(prompt(“Enter a number: “));

// check if number is greater than 0

if (number > 0) {

    console.log(“The number is positive”);

}

// check if number is 0

else if (number == 0) {

  console.log(“The number is zero”);

}

// if number is less than 0

else {

     console.log(“The number is negative”);

}

Run Code

Output

Enter a number: 0

The number is zero.

Check Prime Number

// program to check if a number is prime or not

// take input from the user

const number = parseInt(prompt(“Enter a positive number: “));

let isPrime = true;

// check if number is equal to 1

if (number === 1) {

    console.log(“1 is neither prime nor composite number.”);

}

// check if number is greater than 1

else if (number > 1) {

    // looping through 2 to number-1

    for (let i = 2; i < number; i++) {

        if (number % i == 0) {

            isPrime = false;

            break;

        }

    }

    if (isPrime) {

        console.log(`${number} is a prime number`);

    } else {

        console.log(`${number} is a not prime number`);

    }

}

// check if number is less than 1

else {

    console.log(“The number is not a prime number.”);

}

Output

Enter a positive number: 23

23 is a prime number.