Unit 4
Unit 4
Unit 4
⚫ For creating and formatting tables in web page we have to use <table>
</table> tag.
⚫ The HTML tables allow web authors to arrange data like text, images, links,
other tables, etc. into rows and columns of cells.
⚫ HTML tables are used to manage the layout of the page e.g. header section,
navigation bar, body content, footer section etc. But it is recommended to
use div tag over table to manage the layout of the page .
⚫ Each table row is defined or insert with the <tr> tag.
⚫ A table header is defined with the <th> tag. By default, table headings are
bold and centered.
⚫ A table data/cell is defined or insert with the <td> tag.
Attribute of table tag
<table [align=“left/right”]
[valign=“top/bottom/middle”]
[border=“value”]
[background=“url of image”]
[bgcolor=“color name”]
[bordercolor=“color name”]
[bordercolorlight=“color name”]
[bordercolordark=“color name”]
[cellpadding=“value/value%”]
[cellspacing=“value/value%”]
[height=“value/value%”]
[width=“value/value%”]
[title=“informational tooltip”]>
….
</table>
Table Caption
⚫ The caption tag will serve as a title or explanation for the table and it
shows up at the top of the table.
⚫ The HTML <div> tag is used to group the large section of HTML elements
together.
⚫ The <div> tag defines a division or a section in an HTML document.
⚫ The <div> tag is used to group block-elements to format them with CSS.
⚫ <div> tag is just like a container unit which is used to encapsulate other
page elements and divides the HTML documents into sections.
⚫ The div tag is generally used by web developers to group HTML elements
together and apply CSS styles to many elements at once. For example: If
you wrap a set of paragraph elements into a div element so you can take the
advantage of CSS styles and apply font style to all paragraphs at once
instead of coding the same style for each paragraph element.
⚫ The div tag is not more than a container for other tags. Here are some of the
div's attributes:
⚫ id
⚫ class
⚫ title
⚫ style
⚫ height
⚫ width
Difference between HTML div tag and span tag
⚫<nav>
⚫<a href="/html/">HTML</a>
⚫<a href="/css/">CSS</a>
⚫<a href="/js/">JavaScript</a>
⚫<a href="/jquery/">jQuery</a>
⚫</nav>
Creating User Forms
Text Area
⚫ Text fields that have more than one line and can scroll as the viewer enters
more text. The tag options define the size of the field by the number of
rows and character columns. By adding the option WRAP=VIRTUAL, the
text entered will automatically wrap at the right hand side of the field. You
can also include default text to appear in the field
⚫Creating drop down list
⚫To create a list start with a two sided <select> tag. Within
it place each option in its own <option> tag.
⚫Place the text that you want to appear on the list between
the opening and closing <option >tag.
⚫<p> Color: <select name=“colors” size =“1”>
⚫ <option> Red</option>
⚫<option>Green</option>
⚫<option> Blue</option>
⚫<option> Pink</option>
⚫</select>
⚫</p>
⚫In this code the size attribute is set to 1, which create a
drop down list.
⚫If you set the size attribute to a larger value , the
element appear as a list box.
⚫If there are more item in the list than will fit in the
viewing space, a scroll bar appears automatically at the
right side of the box.
JAVA SCRIPT
⚫ JavaScript is an object-based scripting language that is lightweight and
cross-platform.
⚫ JavaScript is not compiled but translated. The JavaScript Translator
(embedded in browser) is responsible to translate the JavaScript code.
Definition : Javascript is a dynamic computer programming language. It is
lightweight and most commonly used as a part of web pages, whose
implementations allow client-side script to interact with the user and make
dynamic pages. It is an interpreted programming language with object-
oriented capabilities.
⚫ JavaScript was first known as LiveScript, but Netscape changed its name
to JavaScript. Invented in 1995.
Cont…
⚫ The JavaScript code is executed when the user submits the form, and only
if all the entries are valid, they would be submitted to the Web Server.
<h2>Welcome to JavaScript</h2>
<script>
document.write("Hello JavaScript by JavaScript");
</script>
⚫ You can add java script inside <script> </script> tag inside <head> or
<body>, external JavaScript file.
⚫JavaScript can be implemented using JavaScript
statements that are placed within the <script>... </script>.
⚫Syntax:
Here when user press/ click on button one alert message will be display in
browser. Here we click onlick event.
Comment in java script
External javascript
⚫ We can create external JavaScript file and embed it in many html page.
⚫ It provides code re usability because single JavaScript file can be used in
several html pages.
⚫ An external JavaScript file must be saved by .js extension. It is
recommended to embed all JavaScript files into a single file. It increases the
speed of the webpage.
Example of external java script file
function msg(){
alert("Hello Javatpoint");
} //save this file with .js extenssion
Let’s include the JavaScript file into html page. It calls the JavaScript function on button
click.
<html>
<head>
<script type="text/javascript" src="message.js"></script>
</head>
<body>
<p>Welcome to JavaScript</p>
<form>
<input type="button" value="click" onclick="msg()"/>
</form>
</body>
</html>
Here message.js is external javascript file. It include inside html code using src
Variable in javascript
⚫ is simply a name of storage location. There are two types of variables in
JavaScript : local variable and global variable.
⚫ There are some rules while declaring a JavaScript variable (also known as
identifiers).
⚫ Name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ )
sign.
⚫ After first letter we can use digits (0 to 9), for example value1.
⚫ JavaScript variables are case sensitive, for example x and X are different
variables.
<script>
var x = 10;
var y = 20;
var z=x+y;
document.write(z);
</script>
<script>
var data=200;//gloabal variable
function a(){
document.writeln(data);
}
function b(){
document.writeln(data);
}
a();//calling JavaScript function
b();
</script>
JavaScript global variable within function
⚫ To declare JavaScript global variables inside function, you need to
use window object. For example:
window.value=90;
⚫ Access global variable of one function into another function.
function m(){
window.value=100;//declaring global variable by window object
}
function n(){
alert(window.value);//accessing global variable from other function
}
DOM (Document Object Model ) ** important**
⚫ The document object represents the whole html document.
Method Description
<script type="text/javascript">
function totalelements()
{
var allgenders=document.getElementsByName("gender");
alert("Total Genders:"+allgenders.length);
}
</script>
<form>
Male:<input type="radio" name="gender" value="male">
Female:<input type="radio" name="gender" value="female">
<input type="button" onclick="totalelements()" value="Total Genders">
</form>