Lesson 3 : Code some more (Javascript Part) :

Introduction:

In this lesson you will have a recipe table with simple calculation in your website

Aim:

At the least of this lesson, you should have:

Step 1 :

Say hello to the user via an alert box and show their name in your web page. Take a look at Java Script Method and properties. And get start to creat your own alter box!!

Step 2 :

You could improve your recipe table so that it could calculate the quantity of ingredients. For example, if you want make 3 omelette, and you enter 3 as the amount of omelette, then amount of egg and salt you need will be shown in the last column your quantity box.

Example code for JavaScript part

<script>
function get_quantity() {
var quantity = +document.recipe.quantity.value;

var numberofegg = 0;

var amountofsalt = 0;

var eggPerOmelette = 2;

var saltPerOmelette = 50;

numberofegg = quantity * eggPerOmelette;

amountofsalt = quantity * saltPerOmelette;

document.getElementById('numberofegg').value = numberofegg;

document.getElementById('amountofsalt').value = amountofsalt;
}
</script>


You will also need to include three input form in your table. Here is an example of the input form for showing the amount of ingredients you need:

<td colspan="2"><input type="text" name="amountofsalt" id="amountofsalt" readonly="readonly" maxlength="100"/></td>

Self Check Time!!!
Click on if you have done it :

An alert box
A recipe table with simple calculation

(Bcakground picture Source from: Love Wallpaper HD)