Print Table using Javascript

Print Table using Javascript

In today’s tutorial we will learn how to make a function to print mathematics table with user’s input.

Print Table using Javascript output will looks like this:

Now let’s start with the designing part for designing I am using HTML with Bootstrap.

Here is the code for the design :

<!DOCTYPE html>
<html>
<head>
<title>HTML JS</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />

</head>
<body class="bg-dark">
<div class="container">
<div class="row">
<div class="col-md-6 mx-auto bg-light p-5 mt-5">
<h1 class="text-center">Print Table</h1>
<hr/>
<input type="number" class="form-control" id='num1' placeholder="Enter Number Here"/>
<input type="button" onclick="abcd();"class="btn btn-block btn-success mt-4" value="Print">
<div class="mt-3" id='res'>

</div>
</div>
</div>
</div>
</body>
</html>

Now it’s time to code using JavaScript

Step 1. Get value of the input field to create table using loop.

<script>
function abcd(){
var a = document.getElementById('num1').value;
}
</script>

In the above code I have created new function named abcd() to get value of the input field by it’s id name.

Step 2 : Using loop to perform prepare table.

<script type="text/javascript">
function abcd(){
var a = document.getElementById('num1').value;
var b = '<ul class="list-group">';
for(var i=1;i<=10;i++){
var c = a * i;
b += "<li class='list-group-item'>"+c+"</li>";
}
b += "</ul>";
}
</script>

Now everything is set I have create a variable named b to store all the table data.

Step 3 : Now it’s our final step to print data stored in a variable b.
<script type=”text/javascript”>
function abcd(){
var a = document.getElementById(‘num1’).value;
var b = ‘<ul class=”list-group”>’;
for(var i=1;i<=10;i++){
var c = a * i;
b += “<li class=’list-group-item’>”+c+”</li>”;
}
b += “</ul>”;
document.getElementById(‘res’).innerHTML = b;
}
</script>
In the above code I have added new line where I have select res id to print our JavaScript in the innerHTML.

Here is the screenshot for the output:

Here is the complete code to Print Mathematics Table using Javascript:
<!DOCTYPE html>
<html>
<head>
<title>HTML JS</title>
<link rel=”stylesheet” href=”https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css” />
<script type=”text/javascript”>
function abcd(){
var a = document.getElementById(‘num1’).value;
var b = ‘<ul class=”list-group”>’;
for(var i=1;i<=10;i++){
var c = a * i;
b += “<li class=’list-group-item’>”+c+”</li>”;
}
b += “</ul>”;
document.getElementById(‘res’).innerHTML = b;
}
</script>
</head>
<body class=”bg-dark”>
<div class=”container”>
<div class=”row”>
<div class=”col-md-6 mx-auto bg-light p-5 mt-5″>
<h1 class=”text-center”>Print Table</h1>
<hr/>
<input type=”number” class=”form-control” id=’num1′ placeholder=”Enter Number Here”/>
<input type=”button” onclick=”abcd();”class=”btn btn-block btn-success mt-4″ value=”Print”>
<div class=”mt-3″ id=’res’>

</div>
</div>
</div>
</div>
</body>
</html>

That’s all for today hope you guys enjoy this post.

Thanks.

132 thoughts on “Print Table using Javascript

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. I like the valuable information you provide in your articles. I will bookmark your blog and check again here regularly. I’m quite sure I will learn plenty of new stuff right here! Best of luck for the next!

  2. Hello I am so grateful I found your blog page, I really found you by error, while I was researching on Yahoo for something else, Anyways I am here now and would just like to say kudos for a remarkable post and a all round interesting blog (I also love the theme/design), I don’t have time to browse it
    all at the moment but I have saved it and also added in your RSS feeds, so when I have time
    I will be back to read much more, Please do keep up the awesome work.

  3. I was suggested this web site by way of my cousin. I am not positive whether this publish is written by way of him as nobody else know such distinct approximately my difficulty. You are wonderful! Thanks!

  4. Hey there! I’ve been reading your weblog for a long time now and finally got the courage to go ahead and give you a shout out from New Caney Tx! Just wanted to mention keep up the great work!

  5. Wonderful goods from you, man. I have understand your stuff previous to and you’re just extremely wonderful. I actually like what you’ve acquired here, really like what you’re stating and the way in which you say it. You make it enjoyable and you still care for to keep it wise. I can’t wait to read far more from you. This is really a tremendous site.

  6. Hello There. I found your blog using msn. This is a very well written article. I will make sure to bookmark it and return to read more of your useful info. Thanks for the post. I’ll certainly comeback.

  7. you are in reality a just right webmaster. The site loading pace is amazing. It seems that you’re doing any distinctive trick. Furthermore, The contents are masterpiece. you’ve done a great activity in this topic!

  8. You could certainly see your enthusiasm within the work you write. The sector hopes for even more passionate writers such as you who are not afraid to say how they believe. Always follow your heart.

  9. Thank you, I’ve recently been looking for information approximately this subject for a while and yours is the best I’ve found out so far. However, what about the bottom line? Are you certain in regards to the supply?

  10. I just want to say I’m newbie to blogging and site-building and honestly savored your website. More than likely I’m planning to bookmark your blog . You absolutely come with incredible article content. Cheers for revealing your blog.

  11. F*ckin’ amazing issues here. I am very satisfied to look your article. Thank you so much and i’m having a look forward to contact you. Will you kindly drop me a mail?

  12. Together with almost everything which appears to be developing within this subject matter, your perspectives are generally quite radical. On the other hand, I am sorry, because I can not give credence to your whole plan, all be it refreshing none the less. It would seem to us that your comments are actually not completely validated and in actuality you are your self not entirely certain of the assertion. In any event I did enjoy looking at it.

  13. Hmm is anyone else encountering problems with the images on this blog loading? I’m trying to figure out if its a problem on my end or if it’s the blog. Any suggestions would be greatly appreciated.

  14. I’ll right away grab your rss feed as I can’t find your email subscription link or newsletter service. Do you’ve any? Please let me know in order that I could subscribe. Thanks.

  15. You really make it seem so easy with your presentation but I find this topic to be actually something that I think I would never understand. It seems too complex and very broad for me. I am looking forward for your next post, I will try to get the hang of it!

  16. What i don’t realize is actually how you are not actually much more well-liked than you may be right now. You are so intelligent. You realize thus significantly relating to this subject, made me personally consider it from numerous varied angles. Its like women and men aren’t fascinated unless it is one thing to accomplish with Lady gaga! Your own stuffs outstanding. Always maintain it up!

  17. Hello, you used to write fantastic, but the last several posts have been kinda boring… I miss your tremendous writings. Past several posts are just a little bit out of track! come on!

  18. Great post. I was checking continuously this weblog and I am impressed!
    Extremely useful information specifically the closing phase 🙂 I maintain such info
    much. I used to be seeking this certain information for a
    very long time. Thank you and best of luck.

  19. Somebody necessarily lend a hand to make critically articles I would state.

    That is the very first time I frequented your website page and to this point?
    I amazed with the research you made to create this particular submit incredible.
    Great task!

  20. I know this if off topic but I’m looking into starting my own blog and was curious what all
    is needed to get setup? I’m assuming having a blog like yours
    would cost a pretty penny? I’m not very internet savvy so I’m not
    100% certain. Any suggestions or advice would be greatly appreciated.
    Kudos

  21. It’s actually a nice and useful piece of info.
    I’m glad that you shared this helpful information with us.
    Please stay us informed like this. Thank you for sharing.

  22. Your style is really unique in comparison to other folks I have
    read stuff from. I appreciate you for posting when you have the
    opportunity, Guess I’ll just book mark this blog.

  23. My spouse and I absolutely love your blog and find nearly all of your post’s to be just what
    I’m looking for. Does one offer guest writers to write content for you?

    I wouldn’t mind publishing a post or elaborating on some of the
    subjects you write concerning here. Again, awesome web site!

  24. I am really impressed with your writing skills as well as with the layout on your
    blog. Is this a paid theme or did you modify it yourself?
    Anyway keep up the excellent quality writing, it is rare to see a nice blog like
    this one today.

  25. Hi there, I do believe your blog could possibly be having browser compatibility issues.
    When I look at your blog in Safari, it looks fine
    however, when opening in IE, it’s got some overlapping issues.
    I just wanted to give you a quick heads up! Apart from that,
    excellent website!

  26. Hi! This post couldn’t be written any better! Reading through this post
    reminds me of my previous room mate! He always kept chatting about
    this. I will forward this page to him. Pretty sure he will have a
    good read. Thanks for sharing!

  27. An intriguing discussion is worth comment. I think that you ought to publish more about this issue, it may not be a taboo matter but
    generally people do not discuss these issues.

    To the next! All the best!!

  28. It’s appropriate time to make a few plans for the longer term and it’s time to be happy.
    I have read this put up and if I could I desire
    to counsel you some interesting things or advice.
    Perhaps you could write next articles referring to this
    article. I desire to read even more issues approximately it!

  29. Hello there! This blog post couldn’t be written much
    better! Looking through this post reminds me of
    my previous roommate! He continually kept preaching about this.
    I will send this article to him. Fairly certain he’s
    going to have a very good read. I appreciate you for sharing!

  30. Thanks for another great article. Where else could anybody get that kind of info in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.

  31. My partner and I absolutely love your blog and find a lot of your post’s to be exactly
    I’m looking for. can you offer guest writers to write content to suit your needs?
    I wouldn’t mind writing a post or elaborating on many of the subjects you write with regards to here.
    Again, awesome site!

  32. Its like you read my mind! You appear to grasp so much
    about this, like you wrote the e-book in it or something. I believe
    that you just can do with a few percent to force the message home a
    bit, however instead of that, this is wonderful blog.
    A fantastic read. I will definitely be back.

  33. Having read this I thought it was rather enlightening.
    I appreciate you finding the time and effort to put this content together.
    I once again find myself spending way too much time both reading and leaving comments.
    But so what, it was still worthwhile!

  34. Heya i am for the first time here. I came across this board and I find It really useful & it helped me out
    a lot. I hope to give something back and help others like you helped me.

  35. I was recommended this blog through my cousin. I’m
    not positive whether or not this publish is written by way of him as nobody else
    recognize such specified about my problem. You are amazing!
    Thank you!

  36. I’m not sure why but this weblog is loading incredibly slow for me. Is anyone else having this issue or is it a issue on my end? I’ll check back later and see if the problem still exists.

  37. “Terrific work! This is the type of information that should be shared around the web. Shame on Google for not positioning this post higher! Come on over and visit my web site. Thanks =)”

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.