Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cyclesheets
- 1. Write a Php program to display fibonacci series using for and while loop.
- <?php
- $count = 0 ;
- $f1 = 0;
- $f2 = 1;
- echo $f1." , ";
- echo $f2." , ";
- while ($count < 20 )
- {
- $f3 = $f2 + $f1 ;
- echo $f3." , ";
- $f1 = $f2 ;
- $f2 = $f3 ;
- $count = $count + 1;
- }
- ?>
- 2. Write a php code to open a file and perform read, write and update that.
- <?php
- $myfile= fopen(“filename.txt”,a+) or die (“unable to open the file”);
- Echo fread(myfile,filesize(“filename.txt”);
- $txt= “Hi”;
- fwrite($myfile, $txt);
- fclose($myfile);
- ?>
- 3. Write a php code to create a table employee(empno, name, department, salary, designation, date-of-joining), insert 5 records and execute query using php to display name and salary of all employees.
- <?php
- $servername="localhost";
- $username="root";
- $password="";
- $database="myDB";
- $conn=new mysqli("$servername","$username","$password","$database");
- if($conn->connect_error)
- die ("Connection not established");
- $sql = "INSERT INTO employee VALUES(2,'','','','','')";
- $sql = "INSERT INTO employee VALUES(2,'','','','','')";
- $sql = "INSERT INTO employee VALUES(2,'','','','','')";
- $sql = "INSERT INTO employee VALUES(2,'','','','','')";
- $sql = "INSERT INTO employee VALUES(2,'','','','','')";
- if($conn->multi_query($sql)===TRUE)
- echo " created";
- ?>
- 4. Design the following form using php.
- <!DOCTYPE HTML>
- <html>
- <head>
- <style>
- .error {color: #FF0000;}
- </style>
- </head>
- <body>
- <?php
- // define variables and set to empty values
- $nameErr = $emailErr = $genderErr = $websiteErr = "";
- $name = $email = $gender = $comment = $website = "";
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- if (empty($_POST["name"])) {
- $nameErr = "Name is required";
- } else {
- $name = test_input($_POST["name"]);
- // check if name only contains letters and whitespace
- if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
- $nameErr = "Only letters and white space allowed";
- }
- }
- if (empty($_POST["email"])) {
- $emailErr = "Email is required";
- } else {
- $email = test_input($_POST["email"]);
- // check if e-mail address is well-formed
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $emailErr = "Invalid email format";
- }
- }
- if (empty($_POST["website"])) {
- $website = "";
- } else {
- $website = test_input($_POST["website"]);
- // check if URL address syntax is valid (this regular expression also allows dashes in the URL)
- if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
- $websiteErr = "Invalid URL";
- }
- }
- if (empty($_POST["comment"])) {
- $comment = "";
- } else {
- $comment = test_input($_POST["comment"]);
- }
- if (empty($_POST["gender"])) {
- $genderErr = "Gender is required";
- } else {
- $gender = test_input($_POST["gender"]);
- }
- }
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <h2>PHP Form Validation Example</h2>
- <p><span class="error">* required field.</span></p>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- Name: <input type="text" name="name" value="<?php echo $name;?>">
- <span class="error">* <?php echo $nameErr;?></span>
- <br><br>
- E-mail: <input type="text" name="email" value="<?php echo $email;?>">
- <span class="error">* <?php echo $emailErr;?></span>
- <br><br>
- Website: <input type="text" name="website" value="<?php echo $website;?>">
- <span class="error"><?php echo $websiteErr;?></span>
- <br><br>
- Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea>
- <br><br>
- Gender:
- <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female
- <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male
- <span class="error">* <?php echo $genderErr;?></span>
- <br><br>
- <input type="submit" name="submit" value="Submit">
- </form>
- <?php
- echo "<h2>Your Input:</h2>";
- echo $name;
- echo "<br>";
- echo $email;
- echo "<br>";
- echo $website;
- echo "<br>";
- echo $comment;
- echo "<br>";
- echo $gender;
- ?>
- </body>
- </html>
- ///////////////////////////////////////////////////
- cylcesheet1
- 1. HTML EXAMPLE CODE:
- <!DOCTYPE HTML>
- <html>
- <head>
- <title>Name of cities</title>
- </head>
- <body bgcolor="white">
- <h1 style="text-align:center">Delhi</h1>
- <h2>Delhi</h2>
- <h3>Delhi</h3>
- <h4>Delhi</h4>
- <h5>Delhi</h5>
- <h6>Delhi</h6>
- <b>Bangalore</b>
- <u>Bangalore</u>
- <i>Bangalore</i>
- <ul style="list.style.type:disk">
- <li>Apple</li>
- <li>Orange</li>
- <li>Grapefruit</li>
- </ul>
- <ol type="i">
- <li>Apple</li>
- <li>Orange</li>
- <li>Grapefruit</li>
- </ol>
- <dl>
- <dt>HTML</dt>
- <dd>A markup language....</dd>
- <dt>CSS</dt>
- <dd>Language used to...</dd>
- </dl>
- <p>This is my first paragraph</p>
- <p>This is my second paragraph</p>
- <div style="background: skyblue;">
- This is div</div>
- <hr size="5" wodth="70%" />
- <center>Hello World</center>
- <font size="3"
- color="yellow">Font3</font>
- <font size="+4"
- color="yellow">Font+4</font>
- <p><font color="blue">e=mc<sup>2</sup><br>Hello VIT!</font></p>
- <em></em>
- <mark></mark>
- <p>My favourite color is <del>red</del>blue</p>
- </body>
- </html>
- OUTPUT:
- 2. HTML CODE:
- <html>
- <head>
- <title>My First HTML Page</title>
- <meta name="description" content="HTML description"></meta>
- <style type="text/css">
- p { font-size: 12pt; line-height: 12pt; }
- p:first-letter { font-size: 200%; }
- span { text-transform: uppercase; }
- </style>
- </head>
- <body>
- <p>This is my first page....</p>
- <a href="file:///C:/Users/Mokshita/Documents/B.Tech/SEM%206/Web%20Tech/Lab/2.html" title="TimeTable">Link to the timetable</a>
- <br/>
- <img src="C:\Users\Mokshita\Pictures\2L9A5220.JPG" width="50" height="100">Image</img>
- <br/>
- <em>Mokshita</em>
- <br/>
- <strong>Mokshita</strong>
- <br/>
- <b>Mokshita</b>
- <br/>
- <i>Mokshita</i>
- <br/>
- <hr size="5" width="70%" />
- <br/>
- <center>Hello World!</center>
- <br/>
- <font size="3" color="green">Mokshita</font>
- <br/>
- <p><font color="blue">e=mc<sup>2</sup></p>
- <div style="background: skyblue; font-size:24px; color:red">This is a div</div>
- <br/>
- <p>This one is <span style="color:red; font-weight:bold">only a test</span></p>
- <br/>
- <p>Styles demo.<br/>
- <span>Mokshita</span>
- </p>
- <ol type="A">
- <li>Apple</li>
- <li>Orange</li>
- <li>Grape</li>
- </ol>
- <ul type="disk">
- <li>Apple</li>
- <li>Orange</li>
- <li>Grape</li>
- </ul>
- <dl>
- <dt>HTML</dt>
- <dd>It is a markup language...</dd>
- </dl>
- </body>
- </html>
- OUTPUT:
- 3. TABLE Example:
- <html>
- <head>
- <title>Table Example</title>
- </head>
- <body>
- <table border="1">
- <tr>
- <th colspan="4">Table-Assignment</th></tr>
- <tr>
- <th>S.No.</th>
- <th>Type</th>
- <th colspan="2">Details</th>
- </tr>
- <tr>
- <th rowspan="2">1</th>
- <th rowspan="2">Student</th>
- <th>5 rows</th>
- <th>3 columns</th></tr>
- <tr>
- <th>2 ros</th>
- <th>2 columns</th>
- </tr>
- <tr>
- <td>2</td>
- <td>Class</td>
- <th>3 rows</th>
- <th>5 columns</th></tr>
- <tr>
- <td rowspan="2">3</td>
- <td rowspan="2">Subjects</td>
- <th>3 core</th>
- <th>2 electives</th></tr>
- <tr>
- <th>4 core</th>
- <th>1 elective</th>
- </tr>
- </table>
- </body>
- </html>
- OUTPUT:
- 4. Table Example:
- <html>
- <body>
- <tr>
- <th colspna="7">Time Table</th>
- </tr>
- <tr>
- <td rowspan="6">Hours</td>
- <td>MON</td>
- <td>TUES</td>
- <td>WED</td>
- <td>THURS</td>
- <td>FRI</td>
- </tr>
- <tr>
- <td>CAO</td>
- <td>DBMS</td>
- <td>DM</td>
- <td>TOC</td>
- <td>OS</td>
- </tr>
- <tr>
- <td>NW</td>
- <td>CAO</td>
- <td>OS</td>
- <td>DBMS</td>
- <td>DM</td>
- </tr>
- <tr>
- <th colspan="5">Lunch</th>
- </tr>
- <tr>
- <td>NW</td>
- <td>TOC</td>
- <td>CAO</td>
- <td>DM</td>
- <td rowspan="2">Project</td>
- </tr>
- <tr>
- <td>TOC</td>
- <td>NW</td>
- <td>OS</td>
- <td>CAO</td>
- </tr>
- </table>
- </body>
- </html>
- OUTPUT:
- 5. Hyperlink example
- <html>
- <head>
- <title>Simple Tags Demo</title>
- </head>
- <body>
- <a href="C:\Users\Mokshita\Documents\B.Tech\SEM 6\Web\3.html" title="Time Table">This is a link to the time-table.</a>
- <br />
- <img src="C:\Users\Mokshita\Pictures\2L9A5220.JPG" width="100" height="200">Screenshot</img>
- <a href="C:\Users\Mokshita\Pictures\2L9A5220.JPG">Click me</a>
- <br />
- </body>
- </html>
- OUTPUT:
- 6. Hyperlink Example:
- <html>
- <body>
- <ul type="disk">
- <a href="C:\Users\Mokshita\Pictures\2L9A5220.JPG"><li>Sea</li></a>
- <a href="C:\Users\Mokshita\Pictures\2L9A5220.JPG"><li>Mountain</li></a>
- <a href="C:\Users\Mokshita\Pictures\2L9A5220.JPG"><li>Valley</li></a>
- </ul>
- </body>
- </html>
- OUTPUT:
- 7. Form Example:
- <html>
- <body>
- <form name="MyForm" method="get" action="abc.php">
- <fieldset>
- <legend>Student Details</legend>
- <table><tr>Name</tr>
- <tr><input type="text" name="fname" value="Name" size="25"></tr>
- </br>
- <tr>Programmer  UG</tr>
- <tr><input type="radio" name='pgm" value="UG" checked="checked"></tr>
-   PG
- <tr><input type="radio" name='pgm" value="PG"></tr>
- </br>
- <tr>Gender  Male</tr>
- <tr><input type="radio" name="pgm" value="UG"></tr>
-   Female
- <tr><input type="radio" name="pgm" value="PG"></tr>
- </br>
- <tr>Mobile</tr>
- <tr><input type="text" name="number" value="mobile" size="25"></tr>
- </br>
- Gender
- <select name="gender">
- <option value="value1" selected="selected">Male</option>
- <option value="value2">Female</option>
- <option value="value3">Other</option>
- </select>
- </br>
- <input type="submit" name="submitbtn" value="Apply Now"></input>
- </table>
- </fieldset>
- </form>
- OUTPUT:
- 8. Form Example:
- <html>
- <body>
- <form name="MyForm" method="get" action="abc.php">
- <fieldset>
- <legend>Registration Form</legend>
- <table>
- <tr>First Name</tr>
- <tr><input type="text" name="fname" value="Mokshita" size="25"></tr>
- <tr>Last Name</tr>
- <tr><input type="text" name="fname" value="Tyagi" size="25"></tr>
- </br>
- <tr>Gender  Male</tr>
- <tr><input type="radio"></tr>
-   Female
- <tr><input type="radio"></tr>
- </br>
- Country
- <select name="Country">
- <option value="value1" selected="selected">USA</option>
- <option value="value2">India</option>
- <option value="value3">Other</option>
- </select>
- </br>
- <tr>Email</tr>
- <tr><input type="text" name="Email" value="mokshitatyagi429@gmail.com" size="25"></tr>
- </br>
- <tr>Additional Comments</tr>
- <textarea name="message" rows="10" column="20">
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- </textarea>
- <button type="button" onclick=alert('Are you sure?')">Confirm</button>
- </table>
- </fieldset>
- </form>
- OUTPUT:
- 9. Make up three image links and put them in a borderless table. Construct the table so that there is just a little space between the images.
- CODE:
- <html>
- <head>
- <title>Ques6</title>
- </head>
- <body>
- <table cellspacing="0" cellpadding="15">
- <tr>
- <td><img src="C:\Users\Mokshita\Pictures\2L9A5220.JPG width="10" height="10"/>
- </tr>
- <tr>
- <td><img src="C:\Users\Mokshita\Pictures\2L9A5220.JPG width="10" height="10"/>
- </tr>
- <tr>
- <td><img src="C:\Users\Mokshita\Pictures\2L9A5220.JPG width="10" height="10"/>
- </tr>
- </table>
- OUTPUT:
- 10. Frames Example:
- <html>
- <head>
- <title>Frames Example</title></head>
- <frameset cols="180px,*,150px">
- <frame src="left.html"/>
- <frame src="middle.html"/>
- <frame src="right.html"/>
- </frameset>
- </html>
- OUTPUT:
- 11. Create a following page
- Create a link on the second frame and the content of the link should be displayed on the third frame.
- CODE:
- <html>
- <head>
- <title>Frames Example</title></head>
- <frameset rows="50%,*">
- <frame src="a.html" name="upper">
- <frame src="b.html" name="lower">
- </frameset>
- </html>
- b.html
- <html>
- <head>
- <frameset cols="50%,*">
- <frame src="d.html" name="left">
- <frame src="e.html" name="right">
- </frameset>
- </head>
- </html>
- d.html
- <html>
- <head>
- </head>
- <body>
- <a href="1.html" target="right">Home
- </a>
- </body>
- e.html
- <html>
- <head>
- </head>
- <body>
- hello i am e
- </body>
- OUTPUT:
- 12. CSS Example
- <html>
- <head>
- <link rel="stylesheet" style="text/css" href="index.css">
- </head>
- <body>
- <div class="first">
- hello mokshita
- <div class="second">hiiii
- </div>
- </div>
- </body>
- </html>
- Index.css
- div.first{
- color:red;
- background: skyblue;
- }
- div.second{
- color:white;
- background: green;
- }
- Output:
- 13. Embedded styling:
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Style Sheets</title>
- <style type="text/css">
- em {background-color:#8000FF; color:white}
- h1 {font-family:Arial, sans-serif}
- p {font-size:18pt}
- .blue {color:blue}
- </style>
- <head>
- <body>
- <h1 class="blue">A Heading</h1>
- <p>Here is some text. Here is some text. Here
- is some text. Here is some text. Here is some
- text.</p>
- <h1>Another Heading</h1>
- <p class="blue">Here is some more text.
- Here is some more text.</p>
- <p class="blue">Here is some <em>more</em>
- text. Here is some more text.</p>
- </body>
- </html>
- Output:
- 14. External
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
- Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Importing style sheets</title>
- <link type="text/css" rel="stylesheet"
- href="styles.css" />
- </head>
- <body>
- <h1>Shopping list for <em>Monday</em>:</h1>
- <li>Milk</li>
- <li>Bread
- <ul>
- <li>White bread</li>
- <li>Rye bread</li>
- <li>Whole wheat bread</li>
- </ul>
- </li>
- <li>Rice</li>
- <li>Potatoes</li>
- <li>Pizza <em>with mushrooms</em></li>
- </ul>
- <a href="http://food.com" title="grocery
- store">Go to the Grocery store</a>
- </body>
- </html>
- Styles.css:
- a { text-decoration: none }
- a:hover { text-decoration: underline;
- color: red;
- background-color: #CCFFCC }
- li em { color: red;
- font-weight: bold }
- ul { margin-left: 2cm }
- ul ul { text-decoration: underline;
- margin-left: .5cm }
- Output:
- 15. Inline styling
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/ DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Inline Styles</title>
- </head>
- <body>
- <p>Here is some text</p>
- <!--Separate multiple styles with a semicolon-->
- <p style="font-size: 20pt">Here is some
- more text</p>
- <p style="font-size: 20pt;color:
- #0000FF" >Even more text</p>
- </body>
- </html>
- Output:
- 16. Write a script to take three numbers from the user and display the greatest number out of three.
- <html>
- <head>
- <script>
- var theNumber=Number(prompt("Pick a number",""));
- var theNumber2=Number(prompt("Pick another number",""));
- var theNumber3=Number(prompt("Pick another number",""));
- alert("The maximum number is"+" "+Math.max(theNumber,theNumber2,theNumber3));
- </script>
- </head>
- <body>
- </body>
- </html>
- OUTPUT:
- 17. Create a web page containing a clock
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function startTime() {
- var today=new Date();
- var h=today.getHours();
- var m=today.getMinutes();
- var s=today.getSeconds();
- m=checkTime(m);
- s=checkTime(s);
- document.getElementById('txt').innerHTML=h+":"+m+":"+s;
- var t=setTimeout(startTime,500);
- }
- function checkTime(i) {
- if(i<10) {i="0"+i};
- return i;
- }
- </script>
- </head>
- <body onload="startTime()">
- <div id="txt"></div>
- </body>
- </html>
- OUTPUT:
- 18. Create a web page that allows the user to select one or more books by using checkboxes. Display the name of each book and its price. Display the current total in a text box at the bottom of the page. When a book is selected (or unselected), update the total. Use JavaScript to perform any arithmetic operations.
- <html>
- <head>
- </head>
- <body>
- <form action=" " id="theform">
- <fieldset>
- <legend>
- books
- </legend>
- </br>
- <label>
- <input type="checkbox" name="book" value="300" id="b1" onclick="total()"/>
- story 300/-
- </label>
- </br>
- <label>
- <input type="checkbox" name="book" value="500" id="b2" onclick="total()"/>
- romance 500/-
- </label>
- </br>
- <label>
- <input type="checkbox" name="book" value="150" id="b3" onclick="total()"/>
- thriller 150/-
- </label>
- </br>
- <label>
- <input type="checkbox" name="book" value="200" id="b4" onclick="total()"/>
- sgeneral 200/-
- </label>
- </br>
- <label>
- total
- <input value="0.00" readonly="readonly" type="text" id="total"/>
- </label>
- </br>
- </fieldset>
- <input value="submit" type="submit"/>
- <input value="reset" type="reset"/>
- </form>
- <script type-"text/javascript">
- <function total()
- {
- var input=document.getElementById("form");
- var total=0;
- for(var i=0;i<input.length;i++)
- {
- total+=parseFloat(input[i].value);
- }
- }
- document.getElementById("total").value=" "+total;
- }
- </script>
- </html>
- OUTPUT:
- 19. Write a function “multiple” in JavaScript that determines, for a pair of integers, whether the second integer is a multiple of the first. The function takes two integer arguments and return true if the second is the multiple of the first, and false otherwise.
- <html>
- <head>
- <script>
- function multi(){
- var x=document.forms["myForm"]["a"].value;
- var y=document.forms["myForm"]["b"].value;
- var z=y%x;
- if(z==0)
- {
- document.getElementById("demo").innerHTML="is a multiple";
- }
- else
- {
- document.getElementById("demo").innerHTML="is not a multiple";
- }
- }
- </script>
- </head>
- <body>
- <form name="myForm">
- <input type="text" id="a">
- <input type="text" id="b">
- <button type="button" onclick="multi()">click here</button>
- <p id="demo"></p>
- </form>
- </body>
- </html>
- OUTPUT:
- 20. Create a web page with a text box and a button. On click of a button a message box is displayed with the text entered by the user in the textbox.
- <html>
- <head>
- <script>
- function m(){
- var x=document.forms["myForm"]["a"].value;
- window.alert(x);
- }
- </script>
- </head>
- <body>
- <form name="myForm">
- <input type="text" id="a">
- <button type="button" onclick="m()">click here</button>
- </form>
- </body>
- </html>
- OUTPUT:
- 21. Create a web page with an image and a button. On click of a button the image should move horizontally and also on mouse over the size of the image should be changed.
- <html>
- <body>
- <style>
- #animate {
- width: 100;
- height: 100;
- position: absolute;
- background-image: url("Screenshot from 2017-03-24 16:16:37.png");
- }
- </style>
- <script>
- function myMove() {
- var elem=document.getElementById("animate");
- var pos=0;
- var id=setInterval(frame,5);
- function frame() {
- if(pos==350) {
- clearInterval(id);
- } else {
- pos++;
- elem.style.left=pos+'px';
- }
- }
- }
- function mOver(obj) {
- obj.style.height=200;
- obj.style.width=200;
- }
- function mOut(obj) {
- obj.style.height=100;
- obj.style.width=100;
- }
- </script>
- <p>
- <button onclick="myMove()">Click Me</button>
- </p>
- <div id="animate" onmouseover="mOver(this)" onmouseout="mOut(this)"></div>
- </body>
- </html>
- OUTPUT:
- 22. Write the Java Script for the following
- • Generate alert box
- <html>
- <head>
- <script type="text/javascript">
- function Warn(){
- alert("This is a warning message!");
- document.write("This is a warning message!");
- }
- </script>
- </head>
- <body>
- <p>Click the following button to see the result</p>
- <form>
- <input type="button" value="Click me" onclick="Warn();"/>
- </form>
- </body>
- </html>
- OUTPUT:
- • Generate Confirm box
- <html>
- <head>
- <script type="text/javascript">
- function getConfirmation(){
- var retVal=confirm("Do you want to continue");
- if(retVal==true){
- document.write("User wants to continue !");
- return true;
- }
- else{
- document.write("User does not want to continue !");
- return false;
- }}
- </script>
- </head>
- <body>
- <p>Click the following button to see the result:</p>
- <form>
- <input type="button" value="Click me" onclick="getConfirmation():"/>
- </form>
- </body>
- </html>
- OUTPUT:
- • Generate Prompt box
- <html>
- <head>
- <script type="text/javascript">
- function getValue(){
- var retValue=prompt("Enter your name:","your name here");
- document.write("You have entered:"+retVal);
- }
- </script>
- </head>
- <body>
- <p>Click the following button to see the result:</p>
- <form>
- <input type="button" value="Click Me" onclick="getValue();"/>
- </form>
- </body>
- </html>
- OUTPUT:
- • function with an argument that returns a value
- <html>
- <head>
- <script type="text/javascript">
- function total(numberA, numberB)
- {
- return numberA+numberB
- }
- </script>
- </head>
- <body>
- <script type="text/javascript">
- document.write(total(2,3))
- </script>
- <p>The script in the body section calls a function with two arguments: 2 and 3.</p>
- <p>The function returns the sum of these two arguments.</p>
- </body>
- </html>
- OUTPUT:
- • Looping construct and Error handling
- <html>
- <head>
- <script type="text/javascript">
- try
- {
- docutypoment.write("This is an error as document is misspelled as docutypoment");
- }
- catch(errorvariable)
- {
- document.write("An error occured :Error details:"+errorvariable.description);
- }
- </script>
- </body>
- </html>
- Looping:
- <html>
- <head>
- <script type="text/javascript">
- var a=10;
- for(a=11;a<=20;a++)
- {
- document.write(a);
- document.write(" ");
- }
- </script>
- </body>
- </html>
- OUTPUT:
- 23. Write a web application to implement online quiz system. The application includes only client side script.
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <style>
- div#test{ border:#000 1px solid; padding:10px 40px 40px 40px; }
- </style>
- <script>
- var pos = 0, test, test_status, question, choice, choices, chA, chB, chC, correct = 0;
- var questions = [
- [ "Who is the captain of the indian cricket team?", "dhoni", "kohli", "rahane", "B" ],
- [ "who is the president of india?", "A.P.J Abdul Kalam", "Hamid Ansari", "Pranab Mukherjee", "C" ],
- [ "What is the square root of 576?", "24", "22", "26", "A" ],
- [ "What is the capital of Arunachal Pradesh?", "Imphal", "Aizowl", "Itanagar", "C" ]
- ];
- function _(x){
- return document.getElementById(x);
- }
- function renderQuestion(){
- test = _("test");
- if(pos >= questions.length){
- test.innerHTML = "<h2>You got "+correct+" of "+questions.length+" questions correct</h2>";
- _("test_status").innerHTML = "Test Completed";
- pos = 0;
- correct = 0;
- return false;
- }
- _("test_status").innerHTML = "Question "+(pos+1)+" of "+questions.length;
- question = questions[pos][0];
- chA = questions[pos][1];
- chB = questions[pos][2];
- chC = questions[pos][3];
- test.innerHTML = "<h3>"+question+"</h3>";
- test.innerHTML += "<input type='radio' name='choices' value='A'> "+chA+"<br>";
- test.innerHTML += "<input type='radio' name='choices' value='B'> "+chB+"<br>";
- test.innerHTML += "<input type='radio' name='choices' value='C'> "+chC+"<br><br>";
- test.innerHTML += "<button onclick='checkAnswer()'>Submit Answer</button>";
- }
- function checkAnswer(){
- choices = document.getElementsByName("choices");
- for(var i=0; i<choices.length; i++){
- if(choices[i].checked){
- choice = choices[i].value;
- }
- }
- if(choice == questions[pos][4]){
- correct++;
- }
- pos++;
- renderQuestion();
- }
- window.addEventListener("load", renderQuestion, false);
- </script>
- </head>
- <body>
- <h2 id="test_status"></h2>
- <div id="test"></div>
- </body>
- </html>
- OUTPUT:
Add Comment
Please, Sign In to add comment