WEBMSE1
WEBMSE1
7.) Write JavaScript to validate the following fields of the Registration form.
i) Name (field can not be empty)
ii) Age (Number validation)
iii) Password
iv) Confirm Password
Program:
<html>
<head>
<title> Validate the Password </title>
</head>
<script>
function validateForm() {
var pw1 = document.getElementById("pswd1").value;
var pw2 = document.getElementById("pswd2").value;
var name = document.getElementById("fname").value;
var age = document.getElementById("age").value;
if(name == "") {
alert("Enter the Name");
return false;
}
if(age == "") {
alert("Enter the Age");
return false;
}
else if(isNaN(age)||age>100||age<1){
alert("Enter a valid age");
return false;
}
if(pw1 == "") {
alert("Enter the password");
return false;
}
if(pw1.length < 8||pw1.length > 15) {
alert("Password must be minimum 8 and maximum 15 characters");
return false;
}
if(pw2 == "") {
alert("Enter the password");
return false;
}
if(pw1 != pw2) {
alert("Password does not match");
return false;
}
else {
alert ("Your password created successfully");
}
}
</script>
<body>
<form onsubmit ="return validateForm()"><b>
<fieldset>
<legend>Student Information Form</legend><br>
Name : <input type="text" id="fname"><br><br>
Age : <input type="number" id="age"><br><br>
Password : <input type = "password" id="pswd1"><br><br>
Confirm Password : <input type="password" id="pswd2"><br><br>
<input type="submit" value="Submit">
<button type="reset" value="Reset" >Reset</button>
</form>
</body>
</html>
Output:
8.) Write JavaScript to validate the following fields of the Registration form.
i) Name (Name should contains alphabets)
ii)Password (Password should not be less than 6 characters length).
iii) Phone number (Phone number should contain 10 digits only)
Program:
<html>
<head>
<title>Student Information Form</title>
<script type="text/javascript">
function valid()
{
var na = document.getElementById("nm").value;
var pas = document.getElementById("passwd").value;
var mno = document.getElementById("pno").value;
if(na==""||na==null)
{
alert("Enter The Name");
return false;
}
else if(isNaN(pas)||pas.length<6)
{
alert("The password must be minimum 6 and not character");
return false;
}
else if(mno==""||mno==null)
{
alert("Enter The Phone No");
return false;
}
else if(isNaN(mno)||mno.length>10||mno.length<10)
{
alert("The mobile no. always has 10 digit numerical value");
return false;
}
else
alert("The Student Information Submitted Successfully");
}
</script>
</head>
<body>
<form action="" onsubmit="return valid()" method="post"><b>
<fieldset>
<legend>Student Information Form</legend><br>
Name: <input type="text" id="nm"><br><br>
Password: <input type="password" id="passwd"><br><br>
Phone Number: <input type="text" id="pno"><br><br>
<input type="submit" value="Submit">
<button type="reset" value="Reset" >Reset</button>
</fieldset>
</form>
</body>
</html>
Output:
Program:
<html>
<head>
<title>Faculty Information Form</title>
<script type="text/javascript">
function valid()
{
var na = document.getElementById("name").value;
var mail = document.getElementById("email").value;
var addr = document.getElementById("addrs").value;
var mno = document.getElementById("pno").value;
var yearex = document.getElementById("year").value;
if(na==""||na==null)
{
alert("Enter The Name");
return false;
}
else if(mail==""||mail==null)
{
alert("Enter The Email-Id");
return false;
}
else if(addr==""||addr==null)
{
alert("The The Address");
return false;
}
else if(mno==""||mno==null)
{
alert("Enter The Phone No");
return false;
}
else if(isNaN(mno)||mno.length>10||mno.length<10)
{
alert("The mobile no. always has 10 digit numerical value");
return false;
}
else if(isNaN(yearex)||yearex<3)
{
alert("Not Eligible , Experience should be atleast 3 years");
return false;
}
alert("The Faculty Information Submitted Successfully");
}
</script>
</head>
<body>
<form action="" onsubmit="return valid()" method="post"><b>
<fieldset>
<legend>Faculty Information Form</legend><br>
Name : <input type="text" id="name"><br><br>
Email-id : <input type="text" id="email"><br><br>
Address : <input type="text" id="addrs"><br><br>
Phone Number : <input type="text" id="pno"><br><br>
Year-of-Experience : <input type="number" id="year"><br><br>
<input type="submit" value="Submit">
<button type="reset" value="Reset" >Reset</button>
</fieldset>
</form>
</body>
</html>
Output:
10.) Write a JavaScript to design a simple calculator to perform the following
operations: sum, product, difference and quotient.
Program:
<html>
<head>
<title>calculator</title>
<script>
function performop(op)
{
var result=0;
var n1=parseInt(document.getElementById("num1").value);
var n2=parseInt(document.getElementById("num2").value);
if(op=="+"){
var result=n1+n2;
}
else if(op=="-"){
var result=n1-n2;
}
else if(op=="*"){
var result=n1*n2;
}
else{
var result=n1/n2;
}
document.getElementById("res").value=result;
}
</script>
</head>
<body >
<form><b>
<fieldset>
<legend>Calculator</legend><br>
Enter 1st number : <input type="number" name="num1"
id="num1"><br><br>
Enter 2nd number : <input type="number" name="num2"
id="num2"><br><br>
ADD<input type="button" value="+"
onclick="performop(this.value)"/>
SUBSTRACT<input type="button" value="-"
onclick="performop(this.value)"/>
MULTIPLY<input type="button" value="*"
onclick="performop(this.value)"/>
DIVIDE<input type="button" value="/"
onclick="performop(this.value)"/><br><br>
Result<input type="text" name="res" id="res" readonly/>
<button type="reset" value="Reset" >Reset</button>
</fieldset>
</form>
</body>
</html>
Output:
1.) Write a PHP code to Connect to Database, Create a table College (Dname,
Dno, Number_Of_faculty) Insert 3 records of your choice.
Program:
<?php
$servername = "172.16.2.3";
$database = "student";
$username = "student";
$password = "student";
if (!$conn) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "CREATE TABLE college
(
DNo int,
DName varchar(50),
No_of_Faculty int
)";
Program:
<?php
$servername = "172.16.2.3";
$database = "student";
$username = "student";
$password = "student";
if (!$conn) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "CREATE TABLE account
(
AccNo int,
Name varchar(50),
Branch varchar(50),
Balance int
)";
Program:
<?php
$servername = "172.16.2.3";
$database = "student";
$username = "student";
$password = "student";
if (!$conn) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "CREATE TABLE student
(
SNo int,
SName varchar(50),
Percentage int
)";
Program:
<?php
$servername = "172.16.2.3";
$database = "student";
$username = "student";
$password = "student";
if (!$conn) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "CREATE TABLE employee
(
ENo int,
EName varchar(50),
Salary int
)";