Tuesday, 19 November 2013

Create an HTML page to take a number as input from user and display the Multiplication table of the Number in grid as below format using JavaScript:

If User inputs 2 then output will be:-

2x1
=
2
2x2
=
4
2x3
=
6
2x4
=
8
2x5
=
10
2x6
=
12
2x7
=
14
2x8
=
16
2x9
=
18
2x10
=
20

Ans:

<!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></title>

    <script>

        function sai() {

            var no = document.getElementById("txtno").value;
         
            for (var i = 1; i < 11; i++) {
            var res = no * i;
                document.write("<table border=1><tr><td>"+no+"</td><td>"+"*"+"</td><td>"+i+"</td><td>" + "=" + "</td><td>"+res+"</td></tr></table>");

            }
          alert(no)
        }
    
   </script>
  
</head>
<body>
<table>
<tr>
<td>
    <input id="txtno" type="text" />
</td>
<td>
    <input id="Submit1" type="submit" onclick="sai()" value="submit" />

</td>
</tr>
</table>
</body>
</html>

No comments:

Post a Comment