Written by Sri Vamsi Krishna Chirumamilla on April 20, 2014 in JavaScript > Programming

JavaScript to print Multiplication Table of a Number


Get our Latest updates delivered to your mailbox!

In this article we are going to print Multiplication Table of a Number using JavaScript. We take an input from the user and print the multiplication table. We use the onchange event to capture the input provided by the user.

printTable() function

In this function we check whether the input provided by the user is a Number or not using JavaScript’s inbuilt function isNaN(). If the input is numeric then we print the Multiplication table in the mul span tag by concatenating the result to table variable else we display an error message to Enter a valid Number.

Demo Download Source Code

body {
background: #F4F4F4;
font-family: Arial;
margin: 0;
<table border="0" style="margin: 0 auto; width:500px">
		<td colspan="2"><h2>Print Multiplication Table using JavaScript</h2></td>

		<td width="28%">Enter a Number : </td>
		<td><input type="number" onchange="printTable(this)"></td>
		<td colspan="2"><span id="mul"></span></td>

function printTable(num) {
	var input = num.value;
	if(!isNaN(input)) {
		var table="";
		var number="";
		for(i=1;i<=10;i++) {
			number = input * i;
			table +=  input + " * " + i + " = " + number + "<br/>";
		document.getElementById("mul").innerHTML = table;
	else {
		document.getElementById("mul").innerHTML = "Please Enter a valid Number";

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: