Monday, February 1, 2010

Tables in HTML

Tags

In HTML, tables are designed with help of following set of tags:
  • <table></table>
  • <tr></tr> - divides the table into rows
  • <td></> - divides each row into data cells


Example:
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>


Border Attribute
With the help of border attribute, you can specify the thickness of the border for the table.

Headings in a table

The table can contain headings in any place as you like. The headings are enclose between the <th> & </th> tags.


link

JS: Variables and Operators

Variables

JavaScript variables are used to hold values or expressions. A variable can have a short name, like x, or a more descriptive name, like carname.

Rules for JavaScript variable names:
  • Variable names are case sensitive(y ans Y are two different variables)
  • Variable names must begin with a letter or the underscore character.


Declaring(creating) JavaScript Varibales

Creating variables in JavaScript is most often referred to as "declaring" varibles. You can declare JavaScript variables with the var statement:
var x;
var carname;
After, the declaration shown above, the variables are empty(they have no values yet). Values can be assigned to variables at the time of declaration or even at a later point of time. If undeclared variables are assigned with some values, then the variables will automatically be declared.

Redeclaring JavaScript Variables

If by chance some already used variable names are redeclared, then it will not lose its original value.

Note: JavaScript allows you to perform arithmetic operations with JavaScript variables.

JavaScript Operators


JavaScript supports regular Arithmetic and Assignment operators that we see in Java. Below, we have a set of operators given in a table:

Arithmetic Operators

OperatorDescription
+Addition
-Subtraction
*Multiplication
/Divsion
%Modulus
++Increment
--Decrement


The + Operator Used on Strings


The + operator when used with two strings performs concatenation. When a + operator is used between a string and number, the result will be a string again.

Comparison Operators

All the comparison operators used in java are applied here, with the addition of one new operator:
===   -   is exactly equal to(both 'value' and 'type')
Example:
x===5 is true
x==="5" is false
Comparison operators are commonly used with conditional statements.

Other Operators

The remaining operators include the logical and conditional operators. &&, ||, ! are the three logical operators.


link

how & where

Tags


In order to use Javascript, the script code must be enclosed between the following two tags:
<script type="text/Javascript">
</script>


HTML tags inside JavaScript


JavaScript allows HTML tags to be added within it.
<html>
<body>
<script type="text/Javascript>
document.write("<h1>"Hello World!"</h1>");
</script>

</body>
</html>


Handling Simple Browsers


Browsers that do not support JavaScript, will display JavaScript as page content. To prevent them from doing this, and as part of the JavaScript standard, the HTML comment tag should be used to "hide" the Javascript as follows:
<html>
<body>
<script type="text/javascript">
<!--
document.write("Hello World!");
//-->
</script>

</body>
</html>


Where to Put the JavaScript

  • JavaScripts in the body section will be executed WHILE the page loads.
  • JavaScripts in the head section will be executed when CALLED.


Scripts in <head>

Scripts to be executed when they are called, or when an event is triggered, go in head section. Example:
<head>
<script type="text/javascript">
function message()
{
alert("This alert box was called with the onload event"):
}
</script>

</head>

<body onload="message()">
</body>
The alert() function will generate an alert box, when the html page is loaded.


Scripts in <body>

Scripts to be executed when the page loads go in the body section.

Unlimited Scripts

You can place an unlimited number of scripts in your document, so you can have scripts in both the body and the head section.

External JavaScript

If you want to run the same JavaScript on several pages, without having to write the same script on every page, you can write a JavaScript in an external file.

Save the external JavaScript file with a .js file extension. Example:
<head>
<script type="text/javascript" src="xxx.js"></script>
</head>



link

Javascript

What is JavaScript?
  • JavaScript was designed to add interactivity to HTML pages
  • Javascript is a scripting language
  • A scripting language is a lightweight programming language
  • JavaScript is usually embedded diretly into HTML pages
  • JavaScript is an interpreted language (means that scripts execute without preliminary compilation)
  • Everyone can use JavaScript without purchasing a license

What can a JavaScript do?
  • JavaScript gives HTML designers a programming tool
  • JavaScript can put dynamic text into an HTML page
  • JavaScript can react to events
  • JavaScript can read and write HTML elements
  • JavaScript can be used to validate data
  • JavaScript can be used to detect the visitor's browser
  • Javascript can be used to create cookies



link