Tax calculator using Javascript

Hello guys in this tutorial I am going to create 1 page to calculate tax.

Output for our code will looks like this :

Tax calculator using Javascript
Tax calculator using Javascript

Now let’s start with the code:

Step 1 : Design

To make it attractive I have used bootstrap 4 to design this page.

Here is the coding for the design of Tax calculator using Javascript:

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Tax Calculator</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-fluid">
<div class="row">
<div class="col-md-6 bg-light mt-5 mx-auto p-5">
<h1 class="text-center">Tax Calculator</h1>
<hr/>
<div class='form-group'>
<label>Total Amount</label>
<input type="number" class="form-control" id='amount' />
<label>Tax %</label>
<input type="number" class="form-control" id='tax' />
<input type="button" class="btn btn-success mt-3" onclick="calculatetax();" value="Calculate" />
<div class='mt-3' id='result'></div>
</div>
</div>
</div>
</div>
</body>
</html>

In the above code you can see I have create one column using bootstrap 4 and use 2 input elements in it.

Also there is one button which called the function named calculatetax on the click.

Now I am going to create new function named calculatetax() to perform all the calculations.

Here is the code for the same :

<script>
function calculatetax(){
var a = document.getElementById('amount').value; // Getting the value from the input field1
var b = document.getElementById('tax').value; // Getting the value from input field 2
var c = a * b / 100; //calculate total tex on the amount
a = parseInt(a); //convert string to number so that + sign should work as plus operator.
var total = a + c; // Total amount after adding tex
var dd = "<ul class='list-group'><li class='list-group-item'><strong>Total amount : "+total+"</strong></li><li class='list-group-item'>Tax : "+c+"</li><li class='list-group-item'>Base Amount: "+a+"</li></ul>"; //create sting to print on the page
document.getElementById('result').innerHTML = dd; // send data to innerHTML
}
</script>

In the above code I have placed comment with every line to make it easy to understand the code.

The Final Code

Now here is the final code for Tax calculator using Javascript:

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Tax Calculator</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
<script>
function calculatetax(){
var a = document.getElementById('amount').value;
var b = document.getElementById('tax').value;
var c = a * b / 100;

a = parseInt(a);
var total = a + c;
var dd = "<ul class='list-group'><li class='list-group-item'><strong>Total amount : "+total+"</strong></li><li class='list-group-item'>Tax : "+c+"</li><li class='list-group-item'>Base Amount: "+a+"</li></ul>";
document.getElementById('result').innerHTML = dd;
}
</script>
</head>
<body class="bg-dark">
<div class="container-fluid">
<div class="row">
<div class="col-md-6 bg-light mt-5 mx-auto p-5">
<h1 class="text-center">Tax Calculator</h1>
<hr/>
<div class='form-group'>
<label>Total Amount</label>
<input type="number" class="form-control" id='amount' />
<label>Tax %</label>
<input type="number" class="form-control" id='tax' />
<input type="button" class="btn btn-success mt-3" onclick="calculatetax();" value="Calculate" />
<div class='mt-3' id='result'></div>
</div>
</div>
</div>
</div>
</body>
</html>

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

You can download this code from here.

64 thoughts on “Tax calculator using Javascript

Leave a Reply

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

  1. Great work! This is the type of information that should be shared around the net. Shame on the search engines for not positioning this post higher! Come on over and visit my web site . Thanks =)

  2. My coder is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the costs. But he’s tryiong none the less. I’ve been using WordPress on several websites for about a year and am nervous about switching to another platform. I have heard good things about blogengine.net. Is there a way I can import all my wordpress content into it? Any kind of help would be really appreciated!

  3. Youre so cool! I dont suppose Ive read something like this before. So nice to find anyone with some authentic thoughts on this subject. realy thanks for starting this up. this web site is one thing that is needed on the internet, someone with just a little originality. helpful job for bringing one thing new to the web!

  4. Hiya, I am really glad I have found this info. Nowadays bloggers publish just about gossips and web and this is actually annoying. A good website with interesting content, that’s what I need. Thanks for keeping this web site, I’ll be visiting it. Do you do newsletters? Can’t find it.

  5. Thanks , I have recently been searching for info approximately this topic for a while and yours is the best I have found out so far. However, what about the conclusion? Are you positive concerning the supply?

  6. Good day very cool website!! Guy .. Excellent .. Amazing .. I’ll bookmark your blog and take the feeds also¡KI’m satisfied to search out so many helpful info here within the publish, we’d like work out extra strategies on this regard, thanks for sharing. . . . . .

  7. Attractive section of content. I just stumbled upon your weblog and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I’ll be subscribing to your augment and even I achievement you access consistently quickly.

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

  9. Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you can do with a few pics to drive the message home a little bit, but other than that, this is excellent blog. An excellent read. I will certainly be back.

  10. I simply want to mention I am beginner to blogs and actually savored your blog. Very likely I’m going to bookmark your blog . You absolutely have tremendous articles. Regards for sharing your webpage.

  11. Appreciating the time and energy you put into your blog and detailed information you provide. It’s awesome to come across a blog every once in a while that isn’t the same outdated rehashed material. Great read! I’ve saved your site and I’m adding your RSS feeds to my Google account.

  12. Hello there, just became alert to your blog through Google, and found that it’s truly informative. I am gonna watch out for brussels. I?ll be grateful if you continue this in future. Lots of people will be benefited from your writing. Cheers!

  13. It’s a shame you don’t have a donate button! I’d definitely donate to this outstanding blog! I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account. I look forward to brand new updates and will share this site with my Facebook group. Chat soon!

  14. It is the best time to make some plans for the future and it’s time to be happy. I’ve read this post and if I could I desire to suggest you few interesting things or advice. Maybe you could write next articles referring to this article. I desire to read even more things about it!

  15. Thanks for your marvelous posting! I certainly enjoyed reading it, you may be a great author.I will
    ensure that I bookmark your blog and definitely will come back later in life.

    I want to encourage one to continue your great job, have a nice afternoon!

  16. Howdy would you mind stating which blog platform you’re working with? I’m planning to start my own blog soon but I’m having a hard time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something unique. P.S My apologies for being off-topic but I had to ask!

  17. I have been browsing online more than 3 hours today, yet I never found any fascinating article like yours.
    It’s pretty price enough for me. In my view, if all
    site owners and bloggers made good content as you did, the web might be much more useful than ever before.

  18. Thanks for ones marvelous posting! I definitely enjoyed reading it,
    you happen to be a great author. I will be sure to bookmark your blog
    and will come back down the road. I want to encourage you to continue your great posts,
    have a nice afternoon!

  19. I am really impressed with your writing skills and also with the layout on your weblog.
    Is this a paid theme or did you modify it yourself?
    Either way keep up the nice quality writing, it is rare to see a
    nice blog like this one these days.

  20. Incredible! This blog looks exactly like my old one! It’s on a totally different subject but it has pretty
    much the same layout and design. Excellent choice of colors!

  21. I love your blog.. very nice colors & theme. Did you design this website yourself
    or did you hire someone to do it for you? Plz respond as I’m looking
    to design my own blog and would like to know where u got this from.
    thanks

  22. Oh my goodness! Incredible article dude! Thank you, However I
    am having problems with your RSS. I don’t know
    the reason why I am unable to subscribe to it.
    Is there anyone else having identical RSS issues?

    Anyone who knows the answer will you kindly respond?

    Thanx!!

  23. Hi there! I could have sworn I’ve visited this blog before but
    after going through many of the posts I realized it’s new
    to me. Nonetheless, I’m certainly delighted I stumbled
    upon it and I’ll be bookmarking it and checking back regularly!

  24. I just couldn’t depart your web site before suggesting that I extremely enjoyed the standard information an individual provide to
    your guests? Is going to be back steadily in order to check out new posts

  25. Hello there! I know this is kind of off topic but I was
    wondering which blog platform are you using for this website?
    I’m getting tired of WordPress because I’ve had issues with hackers and I’m looking at alternatives
    for another platform. I would be awesome if you could point me in the direction of a good platform.

  26. Great post. I was checking constantly this
    blog and I am inspired! Very useful information particularly the
    remaining part 🙂 I maintain such information a lot.
    I was looking for this particular information for a long time.

    Thanks and good luck.

  27. Aw, this was an exceptionally nice post. Taking the time and actual effort
    to create a great article… but what can I say… I put things off
    a lot and never manage to get anything done.

  28. Greetings! This is my first visit to your blog! We are a group of volunteers and starting a new project in a community in the same
    niche. Your blog provided us beneficial information to work on. You have done a extraordinary job!

  29. I am really enjoying the theme/design of your blog. Do you ever run into any internet browser compatibility issues?
    A number of my blog readers have complained about my site not working correctly
    in Explorer but looks great in Opera. Do you have any tips to help fix this problem?

  30. First of all I want to say superb blog! I had a quick question that I’d like to ask
    if you do not mind. I was interested to find out how you center yourself and clear your
    thoughts before writing. I’ve had trouble clearing my mind
    in getting my thoughts out. I truly do enjoy writing but it
    just seems like the first 10 to 15 minutes are lost just trying
    to figure out how to begin. Any recommendations or
    hints? Cheers!

  31. hi!,I like your writing very a lot! proportion we keep in touch more about your article on AOL?
    I need a specialist on this house to resolve my problem.
    May be that’s you! Taking a look forward to look you.

  32. Excellent weblog here! Additionally your website so much up fast! What host are you the use of? Can I am getting your affiliate hyperlink for your host? I wish my web site loaded up as quickly as yours lol

  33. Greetings! Quick question that’s totally off topic. Do you know how to make your site mobile friendly? My blog looks weird when viewing from my apple iphone. I’m trying to find a theme or plugin that might be able to fix this issue. If you have any suggestions, please share. 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.