0% found this document useful (0 votes)
12 views14 pages

Student Registration Form with Validation

The document describes an HTML program to design a student registration form and validate the form entries using JavaScript. It includes code to create the form fields, validate the entries and display error messages. A second program uses JavaScript to display browser information like user agent, name, version etc on a web page. A third program describes a Java applet to create a basic calculator application with buttons for numbers, operations and display.

Uploaded by

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

Student Registration Form with Validation

The document describes an HTML program to design a student registration form and validate the form entries using JavaScript. It includes code to create the form fields, validate the entries and display error messages. A second program uses JavaScript to display browser information like user agent, name, version etc on a web page. A third program describes a Java applet to create a basic calculator application with buttons for numbers, operations and display.

Uploaded by

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

Program 4

Aim: Write an HTML script to design a registration form for student details & also validate
the entries of form by using Java Script.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Reg Form</title>
<style type="text/css">
body{
font-family: Calibri;
}

input[type="submit"], input[type="reset"]
{width: 77px;
height: 27px;
position: relative;left: 180px;
}
form{
text-align: center;
font-family: Calibri;
font-size: 20px;
border: 3px solid black;
width: 600px;
margin: 20px auto;
}
td {
padding: 10px;
}
td:first-child {
text-align: right;
font-weight: bold;
}
td:last-child
{ text-align:
left;
}
</style>
<script>
function validate() {
var fname = document.reg_form.fname;
var faname = document.reg_form.faname;
var address = document.reg_form.address;
var gender = document.reg_form.gender;
var email = document.reg_form.email;
var mobile = document.reg_form.mobile;
var course = document.reg_form.course;
var city = document.reg_form.city;
var state = document.reg_form.state;
var dist = document.reg_form.dist;

if ([Link] <= 0)
{alert("Name is required");
[Link]();
return false;
}
if ([Link] <= 0) {
alert("Father's Name is required");
[Link]();
return false;
}
if ([Link] <= 0)
{alert("Address is required");
[Link]();
return false;
}
if ([Link] <= 0)
{alert("Gender is required");
[Link]();
return false;
}
if ([Link] <= 0)
{ alert("Email Id is
required");[Link]();
return false;
}
if ([Link] <= 0) {
alert("Mobile number is required");
[Link]();
return false;
}
if ([Link] == "select course")
{alert("Course is required");
[Link]();
return false;
}
return false;
if ([Link] == "select city")
{alert("City is required");
[Link]();
return false;
}
return false;
if ([Link] == "select dist") {
alert("District is required");
[Link]();
return false;
}
return false;
if ([Link] == "select state")
{alert("State is required");
[Link]();
return false;
}
return false;

}
</script>
</head>
<body>
<center><h1>Student Registration Form</h1></center>

<form method="" action="" name="reg_form" onsubmit="return validate()">

<table>
<tr>
<td><label>First Name: </label></td>
<td>
<input type="text" name="fname" placeholder="First Name">
</td>
</tr>
<tr>
<td><label>Father's Name: </label></td>
<td>
<input type="text" name="faname" placeholder="Father's Name">
</td>
</tr>
<tr>
<td><label> Postal Address: </label></td>
<td>
<input type="textarea" size="50" name="address" placeholder="Address">
</td>
</tr>
<tr>
<td><label> Personal Address: </label></td>
<td>
<input type="textarea" size="50" name="address" placeholder="Address">
</td>
</tr>
<tr>
<td><label>Gender: </label></td>
<td>
<input type="radio" name="gender" value="male">Male
<input type="radio" name="gender" value="femele">Female
</td>
</tr>
<tr>
<td><label>City: </label></td>
<td>
<select name="city">
<option value="select city">select city</option>
<option value="Lucknow">Lucknow</option>
<option value="Chandigarh">Chandigarh</option>
<option value="Delhi">Delhi</option>
<option value="Ajmer">Ajmer</option>
</select>
</td>
</tr>
<tr>
<td><label>Course: </label></td>
<td>
<select name="course">
<option value="select course">select course</option>
<option value="Btech">Btech</option>
<option value="MCA">MCA</option>
<option value="MBA">MBA</option>
</select>
</td>
</tr>
<tr>
<td><label>District: </label></td>
<td>
<select name="dist">
<option value="select dist">select district</option>
<option value="Lucknow">Lucknow</option>
<option value="Chandigarh">Chandigarh</option>
<option value="Delhi">Delhi</option>
<option value="Ajmer">Ajmer</option>
</select>
</td>
</tr>
<tr>
<td><label>State: </label></td>
<td>
<select name="state">
<option value="select state">select state</option>
<option value="UP">UP</option>
<option value="Punjab">Punjab</option>
<option value="Delhi">Delhi</option>
<option value="Rajasthan">Rajasthan</option>
</select>
</td>
</tr>
<tr>
<td><label>Pincode: </label></td>
<td>
<input type="number" name="pincode">
</td>
</tr>

<tr>
<td><label>Email Id: </label></td>
<td>
<input type="text" name="email" placeholder="example@[Link]">
</td>
</tr>
<tr>
<td><label>DOB: </label></td>
<td>
<input type="date" name="dob">
</td>
</tr>
<tr>
<td><label>Mobile: </label></td>
<td>
<input type="number" name="mobile">
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Reset">
</td>
</tr>
</table>
</form>
</body>
</html>
Output:
Program 5
Aim: Write a program using Java Script for webpage to display browser information.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Browser Information</title>
</head>
<body>
<h1>Browser Information</h1>
<p id="browser-info"></p>
<script>
// Function to display browser information
function displayBrowserInfo() {
var browserInfo = "User Agent: " + [Link] + "<br>";
browserInfo += "Browser CodeName: " + [Link] + "<br>";
browserInfo += "Browser Name: " + [Link] + "<br>";
browserInfo += "Browser Version: " + [Link] + "<br>";
browserInfo += "Cookies Enabled: " + [Link] + "<br>";
browserInfo += "Platform: " + [Link] + "<br>";
browserInfo += "Language: " + [Link] + "<br>";
browserInfo += "Online: " + [Link] + "<br>";
browserInfo += "Java Enabled: " + [Link]() + "<br>";

[Link]("browser-info").innerHTML = browserInfo;
}

// Call the function when the page loads


[Link] = displayBrowserInfo;
</script>
</body>
</html>
Output-
Program-6
Aim: To write a Java applet to display the application program screen i.e. Calculator.
Steps:
1. Create a text field to accept the expression and display the output also.
2. Create buttons for digits and a decimal point.
3. Create a button to clear the complete expression.
4. Create the buttons for operations, that is for addition, subtraction, multiplication and
division and an equals button to compute the result.
5. Add ActionListener to all the buttons.
6. Compute the result and display in the text field.
Source code:
import [Link].*;
import [Link].*;
import [Link].*;
public class Calculator extends Applet implements ActionListener
{
TextField inp;
//Function to add features to the frame
public void init()
{
setBackground([Link]);
setLayout(null);
int i;
inp = new TextField();
[Link](150,100,270,50);
[Link](inp);
Button button[] = new Button[10];
for(i=0;i<10;i++)
{
button[i] = new Button([Link](9-i));
button[i].setBounds(150+((i%3)*50),150+((i/3)*50),50,50);
[Link](button[i]);
button[i].addActionListener(this);
}
Button dec=new Button(".");
[Link](200,300,50,50);
[Link](dec);
[Link](this);
Button clr=new Button("C");
[Link](250,300,50,50);
[Link](clr);
[Link](this);
Button operator[] = new Button[5];
operator[0]=new Button("/");
operator[1]=new Button("*");
operator[2]=new Button("-");
operator[3]=new Button("+");
operator[4]=new Button("=");
for(i=0;i<4;i++)
{
operator[i].setBounds(300,150+(i*50),50,50);
[Link](operator[i]);
operator[i].addActionListener(this);
}
operator[4].setBounds(350,300,70,50);
[Link](operator[4]);
operator[4].addActionListener(this);
}
String num1="";
String op="";
String num2="";
//Function to calculate the expression
public void actionPerformed(ActionEvent e)
{
String button = [Link]();
char ch = [Link](0);
if(ch>='0' && ch<='9'|| ch=='.')
{
if (![Link](""))
num2 = num2 + button;
else
num1 = num1 + button;
[Link](num1+op+num2);
}
else if(ch=='C')
{
num1 = op = num2 = "";
[Link]("");
}
else if (ch =='=')
{
if(![Link]("") && ![Link](""))
{
double temp;
double n1=[Link](num1);
double n2=[Link](num2);
if(n2==0 && [Link]("/"))
{
[Link](num1+op+num2+" = Zero Division Error");
num1 = op = num2 = "";
}
else
{
if ([Link]("+"))
temp = n1 + n2;
else if ([Link]("-"))
temp = n1 - n2;
else if ([Link]("/"))
temp = n1/n2;
else
temp = n1*n2;
[Link](num1+op+num2+" = "+temp);
num1 = [Link](temp);
op = num2 = "";
}
}
else
{
num1 = op = num2 = "";
[Link]("");
}
}
else
{
if ([Link]("") || [Link](""))
op = button;
else
{
double temp;
double n1=[Link](num1);
double n2=[Link](num2);
if(n2==0 && [Link]("/"))
{
[Link](num1+op+num2+" = Zero Division Error");
num1 = op = num2 = "";
}
else
{
if ([Link]("+"))
temp = n1 + n2;
else if ([Link]("-"))
temp = n1 - n2;
else if ([Link]("/"))
temp = n1/n2;
else
temp = n1*n2;
num1 = [Link](temp);
op = button;
num2 = "";
}
}
[Link](num1+op+num2);
}
}
}
/*
<applet code = [Link] width=600 height=600>
</applet>
*/
To compile and run the program use the following commands :
>>>javac [Link]
>>>appletviewer [Link]
Output

You might also like