index.html(b) Explain the use of HTML table element for designing the web page layouts with appropriate examples.
<html>
<head><title>HTML Form</title>
</head>
<body>
<form action="submit.php" method="post">
Name : <input type="text" name="name" /> <br />
Branch : <input type="text" name="branch" /><br />
Semester : <input type="text" name="semester" /><br />
<input type="submit" value="Submit">
</form>
</body>
</html>
submit.php
<?php
echo "We can access form data with $_POST variable.";
echo "<br />";
echo "Student Details :- ";
echo "<br />";
echo "Name : ".$_POST['name'];
echo "<br />";
echo "Branch : ".$_POST['branch'];
echo "<br />";
echo "Semester : ".$_POST['semester'];
?>
<html>
<head>
<title>Table example</title>
</head>
<body>
<table style="width:100%; float:left; height:auto;" border="1" bordercolor="#000000">
<tr> <td colspan="3" style="width:100%; float:left; height:100px; text-align:center;">Header</td> </tr>
<tr> <td style="width:20%; float:left; height:400px; text-align:center;">Left side bar</td> <td style="width:60%; float:left; height:400px; text-align:center;">Main content</td> <td style="width:20%; float:left; height:400px; text-align:center;">Right side bar</td> </tr>
<tr> <td colspan="3" style="width:100%; float:left; height:50px; text-align:center;">Footer</td> </tr>
</table>
</body>
</html>
<html>(b) Show the use of window object for controlling your browser.
<head>
<title>Javascript Validation</title>
<script type="text/javascript">
function validate(){
var name = document.getElementById("name").value;
var phone = document.getElementById("phone").value;
var email = document.getElementById("email").value;
var phoneRegex = /^\d{10}$/;
if(name == "" && phone == "" || email == ""){
alert("Please fill all fields!");
return false;
}
else if(!phone.match(phoneRegex)){
alert("Please enter 10 digit number!");
return false;
}
else{
var atpos=email.indexOf("@");
var dotpos=email.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length){
alert("Please enter valid e-mail address");
return false;
}
else{
alert("All fields are correct!");
return true;
}
}
}
</script>
</head>
<body>
<form action="#" method="post" onSubmit="return validate()">
Name : <input type="text" id="name" /> <br />
Phone : <input type="text" id="phone" /><br />
Email : <input type="text" id="email" /><br />
<input type="submit" value="Submit">
</form> </body>
</html>
<html>(a) What is document object? Show its use in accessing the form elements with example.
<head>
<title>window object example</title>
<script>
function openWin()
{
myWindow=window.open("","","width=200,height=100");
myWindow.document.write("<p>This is 'myWindow'</p>");
}
function closeWin()
{
myWindow.close();
}
function moveWin()
{
myWindow.moveBy(250,250);
myWindow.focus();
}
function printpage()
{
myWindow.print();
}
function myFunction()
{
myWindow.resizeTo(500,500);
myWindow.focus();
}
</script>
</head>
<body>
<input type="button" value="Open 'myWindow'" onclick="openWin()" />
<input type="button" value="Move 'myWindow'" onclick="moveWin()" />
<input type="button" value="Resize 'myWindow'" onclick="myFunction()" />
<input type="button" value="Print 'myWindow'" onclick="printpage()" />
<input type="button" value="Close 'myWindow'" onclick="closeWin()" />
</body>
</html>
Document Object : When an HTML document is loaded into a web browser, it becomes a document object.
<html>
<head><title>Document Object</title>
<script type="text/javascript">
function countFields(){
alert(document.forms[0].length);
}
function getFields(str){
alert(document.forms[0].elements[str].value);
}
</script>
</head>
<body>
<form action="#">
Name : <input type="text" name="name" /> <br />
Branch : <input type="text" name="branch" /><br />
Semester : <input type="text" name="semester" /><br />
<input type="submit" value="Submit" />
</form>
<input type="button" value="Count form fields" onClick="countFields()" />
<input type="button" value="Value of Name field" onClick="getFields('name')"/>
<input type="button" value="Value of Branch field" onClick="getFields('branch')"/>
<input type="button" value="Value of Semester field" onClick="getFields('semester')" />
</body>
</html>
index.html <html>(b) Explain the PHP arrays with example.
<head><title>Fibonacci Numbers</title>
</head>
<body>
<form action="generate-fibonacci-series.php" method="post">
Number : <input type="text" name="number" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html> generate-fibonacci-series.php <?php
$a = -1;
$b = 1;
$number = $_POST['number'];
for($i=0;$i<$number;$i++){
$c = $a + $b;
echo $c." ";
$a = $b; $b = $c;
}
?>
Numeric Array
<?php
$numbers = array( 1, 2, 3, 4, 5);
foreach( $numbers as $value )
{
echo "Value is $value <br />";
}
?>
Associative Arrays <?php
$studentData = array(
"name" => "Jaydip Panchal",
"branch" => "Information Technology",
"semester" => 8
);
echo "Students Data : <br />";
foreach($studentData as $key=>$value )
{
echo "$key : $value <br />";
}
?>
Multidimensional Arrays
<?php
$marks = array(
"Jaydip Panchal" => array
(
"physics" => 35,
"maths" => 30,
"chemistry" => 39
),
"Arpan Patel" => array
(
"physics" => 30,
"maths" => 32,
"chemistry" => 29
)
); foreach($marks as $key=>$val){
echo "Marks for ".$key."<br />";
foreach($val as $k=>$v){
echo $k.":".$v."<br />";
}
}
?>
session : A session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.
<?php session_start(); ?>
<html>
<head><title>Session management Example</title></head>
<body>
<?php
if(isset($_POST['submit'])){
$_SESSION['age'] = $_POST['age'];
}
if(isset($_SESSION['age']))
{
echo "Your age = ". $_SESSION['age'];
}
else
{
echo "Your age is not set";
}
?>
<form action="#" method="post">
Enter your age <input type="text" name="age" />
<input type="submit" value="Submit" name="submit" />
</form>
</body>
</html>
bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )
name | The name of the cookie. |
value | The value of the cookie. This value is stored on the clients computer |
expire | The time the cookie expires.you'll most likely set this with the time() function plus the number of seconds before you want it to expire. |
path | The path on the server in which the cookie will be available on. |
domain | The domain that the cookie is available to. |
secure | Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client. When set to TRUE, the cookie will only be set if a secure connection exists. |
httponly | When TRUE the cookie will be made accessible only through the HTTP protocol. This means that the cookie won't be accessible by scripting languages, such as JavaScript. |