Attempting to include a standard VAT rate of 5% on the invoice

/* The code format is correct and I don't see any issues on my end, I hope it works well for you. */

I need assistance in adding a fixed VAT (tax) rate of 5%. The tax amount should be displayed on the row, while the total tax should reflect the sum of all taxes. Lastly, the final total should include the total amount of everything. Thank you.

...

Answer №1

It appears that the intention was to calculate the tax amount and incorporate it into the total sum.

I am of the opinion that this approach will prove effective.

$(document).ready(function(){

  $('#addrow').click(function(){
    $('.item-row:last').after('<tr class="item-row"><td class="item-name"><div class="delete-wpr"><textarea>Item Name</textarea><a class="delete" href="javascript:;" title="Remove row">X</a></div></td><td><textarea class="cost">0</textarea></td><td><textarea class="qty">0</textarea></td><td><textarea class="vat 5%">0</textarea></td><td><span class="price">0</span></td> </tr>')
    bind();
  })
bind() ;
 function bind(){
    $('.cost').blur(update_price);
    $('.qty').blur(update_price);
  }


function  update_price(){
     var row =  $(this).parents('.item-row');
     var cost =  row.find('.cost').val();
     var qty =  row.find('.qty').val();
     row.find('.price').html(Number(qty) * Number(cost) );
     update_total()
  }
function update_total(){

  var total = 0 ; 
  $('.price').each(function(i){
    price =  $(this).html();
      if(price > 0){
        total += Number(price);
      }
  })
  var tax = total * 0.05;
  $('#subtotal').html(total);
  $('#tax').html(tax);
  $('#total').html(total+tax);
}
  $('.delete').live('click',function(){
    $(this).parents('.item-row').remove();
    update_total() ;
    
  })
})
* { margin: 0; padding: 0; }
body { font: 14px/1.4 Georgia, serif; }
#page-wrap { width: 800px; margin: 0 auto; }

textarea { border: 0; font: 14px Georgia, Serif; overflow: hidden; resize: none; }
table { border-collapse: collapse; }
table td, table th { border: 1px solid black; padding: 5px; }

#header { height: 15px; width: 100%; margin: 20px 0; background: #222; text-align: center; color: white; font: bold 15px Helvetica, Sans-Serif; text-decoration: uppercase; letter-spacing: 20px; padding: 8px 0px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<!DOCTYPE html>

<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />

<title>Invoice</title>

<link rel='stylesheet' type='text/css' href='css/style.css' />
<script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='js/custom.js'></script>

</head>

<body>

<div id="page-wrap">

<textarea id="header">INVOICE</textarea> 

<div id="identity">

            <textarea id="address">
            text
    text
</textarea>

</div></answer1>
<exanswer1><div class="answer accepted" i="55215787" l="4.0" c="1552880226" a="ViYjMjM3OyYjMjQxO+G7i3QgVuG7i8WCxYLEgw==" ai="7031906">
<p>Probably, I think you wanted to calculate the tax value and add it to the total.</p>

<p>I think this would work.</p>

<p><div>
<div>
<pre class="lang-js"><code>$(document).ready(function(){

  $('#addrow').click(function(){
    $('.item-row:last').after('<tr class="item-row"><td class="item-name"><div class="delete-wpr"><textarea>Item Name</textarea><a class="delete" href="javascript:;" title="Remove row">X</a></div></td><td><textarea class="cost">0</textarea></td><td><textarea class="qty">0</textarea></td><td><textarea class="vat 5%">0</textarea></td><td><span class="price">0</span></td> </tr>')
    bind();
  })
bind() ;
 function bind(){
    $('.cost').blur(update_price);
    $('.qty').blur(update_price);
  }


function  update_price(){
     var row =  $(this).parents('.item-row');
     var cost =  row.find('.cost').val();
     var qty =  row.find('.qty').val();
     row.find('.price').html(Number(qty) * Number(cost) );
     update_total()
  }
function update_total(){

  var total = 0 ; 
  $('.price').each(function(i){
    price =  $(this).html();
      if(price > 0){
        total += Number(price);
      }
  })
  var tax = total * 0.05;
  $('#subtotal').html(total);
  $('#tax').html(tax);
  $('#total').html(total+tax);
}
  $('.delete').live('click',function(){
    $(this).parents('.item-row').remove();
    update_total() ;
    
  })
})
* { margin: 0; padding: 0; }
body { font: 14px/1.4 Georgia, serif; }
#page-wrap { width: 800px; margin: 0 auto; }

textarea { border: 0; font: 14px Georgia, Serif; overflow: hidden; resize: none; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<!DOCTYPE html>

<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />

<title>Invoice</title>

<link rel='stylesheet' type='text/css' href='css/style.css' />
<script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='js/custom.js'></script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why does Axios keep timing out despite successful testing in Postman?

Trying to set up a single request for my app using axios with express/node js. Here is the code snippet that was generated through the Postman app. I have attempted different variations by creating my own form, but I always end up with the same result. co ...

Master the art of filtering rows in an HTML table based on a select option when the mouse is clicked

I am trying to create a table that displays only the rows selected in a dropdown menu. Here is an example: If "All" is selected, the table should display all rows. If "2017" is selected, the table should display only the rows that have "2017" in the sec ...

Deleting Empty Session Data

I have set up sessions for my website. In order to initialize the session, I included the following code on every link of the website: session_start(); if(isset($_SESSION['User'])) { //session_start(); $sesvar = $_REQUEST['sid']; } ...

Prevent any further dissemination if I continue typing repeatedly

As I develop a custom search engine for a website, the search functionality operates through AJAX on keyup events. This means that when you begin typing (assuming you type more than two characters and after any leading or trailing spaces are removed), an A ...

The successful execution of one promise determines the outcome of the $q.all promise

I am currently dealing with a situation where I have three nested promises that I need to refactor into a single $q.all call. The current structure of the code looks like this: ds.saveData(data).then(function (result1){ someOtherVar = result1.Id; ...

Can someone guide me on how to align text to the bottom border of a page?

Is there a way to adjust the position of the header text ("bottom text") so that it appears just above the bottom border of the page? I have attempted modifying styles and classes within the footer, style, and h3 tags but have not had any success. Below ...

Determine the DOM element that corresponds to a right-click action

I utilized the code snippet below to construct a personalized context menu: <script type="text/javascript"> $(document).ready(function() { var x, y; document.oncontextmenu = function(e) { e.preventDefault(); x = e.clientX; ...

Using a data loader with react-router

I am currently working on a react app where I have implemented routes using the new data loaders from react-router-dom import { RouterProvider, createBrowserRouter, createRoutesFromElements, Route } from 'react-router-dom'; import Home fr ...

Troubleshooting Recursive Logic Problem with hasOwnProperty in JavaScript and JSON

JSON data with a specific problem highlighted by the comment // doesn't get parsed currently: var oarsObject = [{ "coordinateReferenceSystem": "26782,15851 <-- not in a value", "positionReferenceType": "geogWgs84", "geogWgs84": ...

Creating a personalized avatar using Bootstrap 5

Currently, I am working with Bootstrap 5 and am trying to create an avatar with different icons inside it, similar to a letter avatar. I want to have a placeholder where the icon can be added within it. Here is an example of what I have tried: <div widt ...

Using PHP's include/require method with a dynamic path

Looking for assistance with my issue! Ajax is returning the correct information and displaying it in an 'alert(html)' on 'success'. The PHP code echoes $idName and $path correctly on the carrier page where the code resides. There are no ...

Having trouble with the $push operator in Mongo DB?

I am facing an issue while attempting to store data in an array within an object in a Mongo model by utilizing the req.params method. Unfortunately, I encounter the following error: MongoError: cannot use the part (friends of friends.username) to traverse ...

Updating user credits through the Model::factory() method is a common practice in my workflow

I need to update the UserCredits after a purchase. For example, if a user currently has 10 credits and purchases 10 more, I want to add the purchased credits to their existing total. The goal is to increment the current credit score with the new credits ...

The comparison between "rxjs-tslint" and "rxjs-tslint-rules" npm packages

Previously, I utilized the rxjs-tslint-rules package to identify RxJS-related issues in my projects. This package was included in the devDependencies section of my projects' package.json files. Now, there is a new rxjs-tslint package that introduces ...

Increase the size of the box-shadow so that it extends beyond the boundaries

Can we create a wider box-shadow in CSS than the actual HTML element it is being applied to, while maintaining the same height as the element? Increasing the spread of the shadow typically increases the height as well. In the provided code snippet, the max ...

Unexpected patterns observed when utilizing parent/child routing files

I am working with a Node/Express backend that is implemented using TypeScript. Whenever I make changes to a file and save it, if I test the root route in Postman localhost:8000/, I receive the expected response. However, when I test localhost:8000/user af ...

Associate keys with strings and then map them to a specific type of strings in Typescript

I am endeavoring to develop a React component that extends the Octicons icon library available from Github at @githubprimer/octicons-react. One of the components exported by the library is the iconsByName type, which has the following structure: type ico ...

Is there a way to align six columns on the left side and have a dynamic column on the right that fills the width of the browser window?

Is there a way to make a fluid container in Bootstrap 5 that contains a normal container on the left with 6 columns of content, while allowing the right side of the container to expand to the end of the browser window? When using a normal fluid container, ...

Position flex-box items to align with the baseline of the final line of text within a block

I am attempting to replicate the layout shown in the final example of the image linked below using flexbox. It seems that the align-items: baseline; property works perfectly when the blocks contain only one line of text. However, when the left and right ...

The relative link feature in React Router fails to properly navigate

Currently, I am utilizing the npm package react-router-relative (https://www.npmjs.com/package/react-router-relative) for my project. However, it seems to be having trouble properly switching the URL. Here is how my links are configured: <Link to=&apo ...