Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ACTIVITY 3
- 1. Validate the form that you have designed already using Javascript.
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function validateForm(){
- var x = document.forms["myForm1"]["fname"].value;
- if (x == ""){
- alert("Name must be filled out");
- return false;
- }
- var y = document.forms["myForm1"]["age"].value;
- if (y < 0 || y > 100){
- alert("Please input proper age");
- return false;
- }
- }
- </script>
- </head>
- <body>
- <form name="myForm1" onsubmit="return validateForm()" method="post">
- Name:
- <input type="text" name="fname"> <br>
- Age:   
- <input type="number" name="age">
- <br>
- <br>
- <input type="submit" value="Submit">
- </form>
- </body>
- </html>
- 2. Javascript Event handling (Use onblur, onfocus, onload, onunload, onmouseover,onmouseout, onsubmit, ondblclick,onclick )
- <!DOCTYPE html>
- <html>
- <body>
- <script>
- function myFunction {
- return p1 * p2;
- }
- document.getElementById("demo").innerHTML = myFunction;
- </script>
- <button
- onclick="document.getElementById('demo').innerHTML='clicked'"
- onmouseover="document.getElementById('demo').innerHTML='mouse_hover'"
- onmouseout="document.getElementById('demo').innerHTML='mouse_out'"
- onblur="document.getElementById('demo').innerHTML='blur'"
- onfocus="document.getElementById('demo').innerHTML='focus'"
- onload="document.getElementById('demo').innerHTML='load'"
- onunload="document.getElementById('demo').innerHTML='unload'"
- onmouseover="document.getElementById('demo').innerHTML='mouseover'"
- onmouseout="document.getElementById('demo').innerHTML='mouseout'"
- ondblclick="document.getElementById('demo').innerHTML=double_click"
- >Do anything</button>
- <form onsubmit="myFunction()">
- <input type="submit" value="Submit">
- </form>
- <script>
- function myFunction() {
- alert("The form was submitted");
- }
- </script>
- <p id="demo"></p>
- </body>
- </html>
- Activity 4
- 13BCE0038
- 1)Write a function to create a user defined table, accepting rows and columns
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset=utf-8 />
- <title>Change the content of a cell</title>
- <style type="text/css">
- body {margin: 30px;}
- </style>
- </head><body>
- <table id="myTable" border="1">
- </table><form>
- <input type="button" onclick="createTable()" value="Create the table">
- </form></body></html>
- java script function-
- function createTable()
- {
- rn = window.prompt("Input number of rows", 1);
- cn = window.prompt("Input number of columns",1);
- for(var r=0;r<parseInt(rn,10);r++)
- {
- var x=document.getElementById('myTable').insertRow(r);
- for(var c=0;c<parseInt(cn,10);c++)
- {
- var y= x.insertCell(c);
- y.innerHTML="Row-"+r+" Column-"+c;
- }
- }
- }
- 2)Remove items from a dropdown list
- <!DOCTYPE html>
- <html><head>
- <meta charset=utf-8 />
- <title>Remove items from a dropdown list</title>
- </head><body><form>
- <select id="colorSelect">
- <option>Red</option>
- <option>Green</option>
- <option>White</option>
- <option>Black</option>
- </select>
- <input type="button" onclick="removecolor()" value="Select and Remove">
- </form></body></html>
- java script function-
- function removecolor()
- {
- var x=document.getElementById("colorSelect");
- x.remove(x.selectedIndex);
- }
- 3)
- <!DOCTYPE html>
- <html><head>
- <meta charset=utf-8 />
- <style type="text/css">
- body {margin: 30px;}
- </style>
- <title>Count and display items of a dropdown list - w3resource</title>
- </head><body><form>
- Select your favorite Color :
- <select id="mySelect">
- <option>Red</option>
- <option>Green</option>
- <option>Blue</option>
- <option>White</option>
- </select>
- <input type="button" onclick="getOptions()" value="Count and Output all items">
- </form></body></html>
- java script function-
- function getOptions()
- {
- var x=document.getElementById("mySelect");
- var txt1 = "No. of items : ";
- var i;
- l=document.getElementById("mySelect").length;
- txt1 = txt1+l;
- for (i=0;i<x.length;i++)
- {
- txt1 = txt1 + "\n" + x.options[i].text;
- }
- alert(txt1);
- }
- <HTML>
- <HEAD>
- <TITLE>
- 14BCE0097 ullas ghosh DETAILS HTML FORM
- </TITLE>
- </HEAD>
- <body style="background-color:powderblue;">
- <table style="background-color:green;width:100%">
- <tr>
- <th><H1>Name: ullas ghsoh</H1><br><pre>Email Id: Ullasghosh2014@vit.ac.in</pre><pre>Contact Number: (+91) 9944490902.</pre></th>
- <th><img src="" alt="Profile pic" style="width:150px;height:150px;border:1px;" ></th>
- </tr></table><hr>
- <table><td><p>status:</p></td><td><marquee direction="left" scrollamount="10" width="100%">Currently in CSE326: IWP lab doing nothing.</marquee></td></table>
- <hr><H3>Details</H3><hr>
- <table style="margin-left:100px;border:1;padding:5;width:70%;" >
- <tr>
- <td>Father's Name:</td>
- <td>Anil Batra</td>
- </tr>
- <tr>
- <td>Address</td>
- <td>#108, Brindavan residency, Above Tom's Diner, Opp. VIT main gate <br> Vellore, TN</td>
- </tr>
- <tr>
- <td>PIN Code</td>
- <td>632014</td>
- </tr>
- <tr>
- <td>Age</td>
- <td>21</td>
- </tr>
- </table><hr>
- <H3>About</H3><hr>
- <p>Hey! This is ullas ghsoh and I am currently pursuing B.Tech in Computer Science. I am in final year as of now. I do not know, what else do I have to write here. So i'd rather end this now. Okay, thanks! </p>
- </BODY>
- </HTML>
- FORM WITH JSP FORM VALIDATION
- <!DOCTYPE>
- <html>
- <head>
- <style>
- body{background-color:powderblue;}
- h1{color:black;}
- </style>
- <h1><center>DETAILS VERIFICATION FORM</center></h1>
- </head>
- <body>
- <script type="text/javascript">
- function validate(details_form,email)
- {
- /*JAVASCRIPT REGULAR EXPRESSION VALIDATION*/
- var reg= /^([A-Za-z0-9_\-\.])({\@A-Za-z0-9_\-\.]){1,}\.([A-Za-z]{2,4})$/;
- var adress= document.forms[form-id].elements[phone no].value;
- var adress= document.forms[form-id].elements[URL].value;
- var adress= document.forms[form-id].elements[IP adress].value;
- var adress= document.forms[form-id].elements[mac adress].value;
- var adress= document.forms[form-id].elements[email id].value;
- var adress= document.forms[form-id].elements[PAN no].value;
- var adress= document.forms[form-id].elements[drivers lisence].value;
- var adress= document.forms[form-id].elements[ISBN].value;
- var adress= document.forms[form-id].elements[ISSN number].value;
- if(reg.test(details)==false)
- {
- alert("validation unsuccessful please enter the right details");
- return false;
- }
- </script>
- <form id="details_form" method="get" action="submit_successful.html" onsubmit="javascript:return validate('details_form','email');">
- <p>enter phone no here</p>
- <input type="text" name="phone no" size=40><br/>
- <p> enter URL</P>
- <input type="text" name="phone no" size=40><br/>
- <p>enter ip adress</p>
- <input type="text" name="phone no" size=40><br/>
- <p>enter mac address</p>
- <input type="text" name="phone no" size=40><br/>
- <p>enter email id</p>
- <input type="text" name="phone no" size=40><br/>
- <p>enter PAN number</p>
- <input type="text" name="phone no" size=40><br/>
- <p>driving liscence no.</p>
- <input type="text" name="phone no" size=40><br/>
- <p>enter ISBN number</p>
- <input type="text" name="phone no" size=40><br/>
- <p>enter ISSN number</p>
- <input type="text" name="phone no" size=40><br/>
- <input type="submit" value="submit"/>
- </body>
- </html>
- 13BCE0038_activity_7.php
- HTML FORM PHP VALIDATION
- <!DOCTYPE html>
- <html>
- <style>
- input[type=text], select {
- width: 100%;
- padding: 12px 20px;
- margin: 8px 0;
- display: inline-block;
- border: 1px solid #ccc;
- border-radius: 4px;
- box-sizing: border-box;
- }
- input[type=submit] {
- width: 100%;
- background-color: #4CAF50;
- color: white;
- padding: 14px 20px;
- margin: 8px 0;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- }
- input[type=submit]:hover {
- background-color: #45a049;
- }
- div {
- border-radius: 5px;
- background-color: #f2f2f2;
- padding: 20px;
- }
- iframe {
- background-color:#DEF0DA;
- text-color:white
- }
- </style>
- <body>
- <?php
- $name = $regno = $gender = $email = $mobno =$branch = "";
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- $name = test_input($_POST["name"]);
- $reno = test_input($_POST["regno"]);
- $gender = test_input($_POST["gender"]);
- $email = test_input($_POST["email"]);
- $mobno = test_input($_POST["mobno"]);
- $gender = test_input($_POST["gender"]);
- $branch = test_input($_POST["branch"]);
- }
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <iframe src="top.html" width=100% style="border:none;"></iframe>
- <div>
- <form action="13BCE0038_activity_7.php" method="get">
- <input type="text" id="name" name="name" placeholder="Name">
- <input type="text" id="regno" name="regno" placeholder="Register Number">
- <input type="radio" id="gender" name="gender" value="male">Male
- <input type="radio" id="gender" name="gender" value="female">Female
- <input type="text" id="email" name="email" placeholder="E-mail">
- <input type="text" id="mobno" name="mobno" placeholder="Mobile Number">
- <select id="branch" name="branch">
- <option value="none">Select Your Branch</option>
- <option value="cse">CSE</option>
- <option value="it">IT</option>
- </select>
- <input type="submit" value="Submit Information">
- </form>
- </div>
- <?php
- echo "<h2>Your Input:</h2>";
- echo $_GET["name"];
- echo "<br>";
- echo $_GET["regno"];
- echo "<br>";
- echo $_GET["gender"];
- echo "<br>";
- echo $_GET["email"];
- echo "<br>";
- echo $_GET["mobno"];
- echo "<br>";
- echo $_GET["branch"];
- ?>
- </body>
- </html>
- ========================================================================================================================================================================================================================================================================================
- top.html
- <!DOCTYPE html>
- <html>
- <style>
- body {
- text-align:'center'
- }
- </style>
- <body>
- <p><font align=center color="#347642"><h1 align="center">Student Information</h1></font>
- <font color="#347642"><i><h3 align="center">Student Information</h3></i></font>
- </p>
- </body>
- </html>
- Activity 9
- 13BCE0038
- PHP with Database connection:
- HT.html
- <html>
- <body>
- <form action="db.php" method="post">
- Name: <input type="text" name="fname" />
- Age: <input type="text" name="age" />
- <input type="submit" />
- </form>
- </body>
- </html>
- Include.php
- <?php
- $username = "s
- cse
- ";
- $password = "
- scse
- ";
- $hostname = "localhost";
- //connection to the database
- $dbhandle = mysql_connect($hostname, $username, $password)
- or die("Unable to connect to MySQL");
- echo "Connected to MySQL<br>";
- ?>
- Db.php
- <?php
- require_once("incl
- ude.php");
- $a=$_POST['fname'];
- $b=$_POST['age'];
- //select a database to work with
- $selected = mysql_select_db("ramani",$dbhandle)
- or die("Could not select ramani");
- //execute the SQL query and return records
- //$abc=mysql_query("create table rajkumar
- (dept char(4))");
- $result1s = mysql_query("insert into raj values('sourav','25')");
- //$result1s = mysql_query("insert into raj values('$a','$b')");
- $result = mysql_query("SELECT name, age FROM raj");
- echo mysql_num_rows($result)."<br>";
- echo mysql_num_fie
- lds($result)."<br>";
- //fetch tha data from the database
- while ($row = mysql_fetch_array($result)) {
- echo "NAME:".$row{'name'}." AGE:".$row{'age'}."<br>";//display the
- results
- }
- //print_r(mysql_fetch_row($result));
- //print_r(mysql_fetch_assoc($resul
- t));
- //close the connection
- mysql_close($dbhandle);
- ?>
- HINT:
- To access the mysql
- mysql
- –
- u scse
- -
- p
- ## DBMS WITH SQL
- connect.php
- <?
- $host="localhost"; // Host name.
- $db_user="root"; // MySQL username.
- $db_password=""; // MySQL password.
- $database="test"; // Database name.
- $link = mysql_connect($host,$db_user,$db_password);
- if (!$link) {
- die('Could not connect: ' . mysql_error());
- }
- else
- {
- echo "Mysql Connected Successfully";
- }
- mysql_close($link);
- Create a Index.html using ajax
- <html>
- <head>
- <script type="text/javascript">
- function checkmyconnect()
- {
- var xmlhttp;
- if (window.XMLHttpRequest)
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
- }
- }
- xmlhttp.open("GET","connect.php",true);
- xmlhttp.send();
- }
- </script>
- </head>
- <body>
- <h2>Let Connect to mysql in html file</h2>
- <div id="myDiv">No connection</div>
- <button type="button" önclick="checkmyconnect()">Check Mysql connection</button>
- </body>
- </html>
Add Comment
Please, Sign In to add comment