Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1 class="title">Booking</h1>
<form action="" method="post">
  <div class="header">
    <h2>Category</h2>
    <h2>Amount</h2>
    <h2>Price</h2>
</div>
  <div class="row">
    <label for="">1st Category</label>
    <div class="input__field">
      <button class="fa-solid fa-minus down"></button>
      <input type="number" value="0" min="0">
      <button class="fa-solid fa-plus up"></button>
    </div>
    <label class="price" for="">$300</label>
  </div>
   <div class="row">
    <label for="">2nd Category</label>
    <div class="input__field">
      <button class="fa-solid fa-minus down"></button>
      <input type="number" value="0" min="0">
      <button class="fa-solid fa-plus up"></button>
    </div>
    <label class="price" for="">$400</label>
  </div>
  <div class="row">
    <label for="">3rd Category</label>
    <div class="input__field">
      <button class="fa-solid fa-minus down"></button>
      <input type="number" value="0" min="0">
      <button class="fa-solid fa-plus up"></button>
    </div>
    <label class="price" for="">$500</label>
  </div>
  <div class="total">Total: $<span>0</span></div>
  <button class="submit" type="submit">Buy</button>
</form>
              
            
!

CSS

              
                body {
  background: #88f1;
}

input[type=number]::-webkit-inner-spin-button {
  display: block;
  // -webkit-appearance: none;
  appearance: none;
}

.input__field button {
  box-shadow: -1px -1px 3px 0 #fff, 1px 1px 3px 0 #0003;
  // display:flex;
  // width: 10px;
  // justify-content: space-around;
}

body {
  height:100vh;
  display:flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.title {
  font-family: Lato;
  font-weight:900;
  font-size: 2rem;
  padding: 1rem;
}

.row {
  display:flex;
  justify-content: space-around;
  align-items: center;
}

.header {
  display:flex;
  justify-content: space-around;
}

.header h2 {
  font-weight: 400;
  padding: 0 0 1rem;
  color: #fff;
  text-shadow: 1px 1px 2px #0009, -1px -1px 2px #fff;
}

form {
  display: flex;
  flex-direction: column;
  font-family: Lato;
  width: 500px;
}

form input {
  background: #55f1;
  font-family: Lato;
  font-size: .8rem;
  outline: none;
  border: 1px solid #0003;
  border-radius: .5rem;
  padding: .3rem;
  // margin:.3rem;
  width:50px;
  text-align: center;
  box-shadow: -1px -1px 2px 0 #fff inset, 1px 1px 2px 0 #0002 inset;
}

label {
  width :100px;
  color: #333c;
}

.submit {
  font-size: .8rem;
  padding: .5rem 1rem;
  border: 1px solid #0003;
  border-radius: 0.5rem;
  background: lightblue;
}

.price {
  text-align: center;
}

.input__field button {
  padding: .35rem;
   // width: 20px;
   //  height:20px;
  background: none;
  border: 1px solid #0003;
  border-radius: 3rem;
font-family: Fontawesome;
  font-weight: 100;
  color: #0007;
}

.input__field button:hover {
  background: #f55;
  color:#000;
}

.total {
  margin:1rem 0;
}
.total span {
  color: #f55;
}
              
            
!

JS

              
                let btnUp = document.querySelectorAll(".up"),
    btnDown = document.querySelectorAll(".down"),
    input = document.querySelectorAll("input");

input.forEach(item => {
  item.addEventListener('keypress', function(e) {
    if(e.key === "Enter") {
      e.preventDefault();
      sum();
    }
  });
  item.addEventListener('blur', function(e) {
    item.value = item.value === '' ? 0 : item.value ;
    sum();
  });
});

btnDown.forEach(item => {
  item.addEventListener('click', function(e) {
    e.preventDefault();
    if (item.parentNode.querySelector("input").value > "0") {
      item.nextElementSibling.stepDown();
    };
    sum();
  });
});

btnUp.forEach(item => {
  item.addEventListener('click', function(e) {
    e.preventDefault();
    item.previousElementSibling.stepUp();
    sum();
  });
})

function sum() {
  let total = 0;
  let inputField = document.querySelectorAll(".row");
  inputField.forEach(item => {
  let value = item.querySelector("input").value;
  console.log(value);
  let price = item.querySelector(".price").innerText.replace('$','');
  total = total + value * price;
  document.querySelector('.total').children[0].innerHTML = total;
});  
}


              
            
!
999px

Console