Whenever I press a button, my card holder gradually slides downwards

I'm facing an issue with my code and I'm unsure whether it's related to CSS or JavaScript. Whenever I click the button on my page, my card-container2 moves downward unexpectedly. Here is the snippet of my code:

HTML:

<div class="card-container">
    <h1>splitter bill</h1>
    <p>enter the name of the person and his amount (21% of iva included):</p>
    <label id="name-text">Nombre</label>
    <br>
    <input type="text" id="name">
    <br>
    <label id="monto-texto">amount</label>
    <br>
    <input type="number" id="amount">
    <br>
    <button id="calculate">Ingresar</button>
    <p>Total: <span id="total"></span> </p>
    <div id="each-person">
    </div>
    <p> Cada uno le toca aportar: <span id="split"></span> </p>
</div>
<div class="card-container2">
    <div id="clima">   
    </div>
</div>

JavaScript:

//more js code available upon request 
function defineTotal() {

  personsListHTMLelemento = "";

  let list = "";
  let total = 0;

  for (let i = 0; i < persons.length; i++) {
    total += persons[i].amount
    list += `${persons[i].name}: ${persons[i].amount} <br>`;
  }

  let iva = 1.21

  totalHTMLelemento.innerHTML = total * iva;
  personsListHTMLelemento.innerHTML = list;
  splitHTMLelemento.innerHTML = (total * iva) / persons.length;

CSS:

.card-container {
    margin-left: 500px;
    margin-right: 500px;
    padding-left: 50px;
    background-color: #302b63;
    border-radius: 20px;
    margin-top: 150px;
}

.card-container2 {
    margin-left: 1270px;
    padding-left: 35px;
    background-color: #302b63;
    border-radius: 5px;
    margin-top: -490px;
}

If you require more CSS/JavaScript code, feel free to ask and I will provide it.

Answer №1

I tried to replicate the error but couldn't, however, if the code above is yours, you are missing a closing } at the end of your script.

function defineTotal() {

personsListHTMLelemento = "";

let list = "";
let total = 0;

for (let i = 0; i < persons.length; i++) {
  total += persons[i].amount
  list += `${persons[i].name}: ${persons[i].amount} <br>`;
}

let iva = 1.21

totalHTMLelemento.innerHTML = total * iva;
personsListHTMLelemento.innerHTML = list;
splitHTMLelemento.innerHTML = (total * iva) / persons.length;
    }
.card-container {
margin-left: 500px;
margin-right: 500px;
padding-left: 50px;
background-color: #302b63;
border-radius: 20px;
margin-top: 150px;
}

.card-container2 {
margin-left: 1270px;
padding-left: 35px;
background-color: #302b63;
border-radius: 5px;
margin-top: -490px;
}
<div class="card-container">
<h1>splitter bill</h1>
<p>enter the name of the person and his amount (21% of IVA included):</p>
<label id="name-text">Nombre</label>
<br>
<input type="text" id="name">
<br>
<label id="monto-texto">amount</label>
<br>
<input type="number" id="amount">
<br>
<button id="calculate">Ingresar</button>
<p>Total: <span id="total"></span> </p>
<div id="each-person">
</div>
<p> Each one has to contribute: <span id="split"></span> </p>
</div>
<div class="card-container2">
<div id="weather">
</div>
</div>

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

Transitioning jQuery .load and the usage of sorttable.js for sorting data

My jQuery code snippet is as follows: $("#loadBtn").click(function(){ $('#div1').delay(200).slideUp('slow') .load ('page2.php #div2').hide().delay(300).slideDown('slow'); return false; ...

Enhancing time slot height on Fullcalendar V5: A step-by-step guide

Curious about adjusting the height of time slots in Fullcalendar V5 - any tips? ...

Having difficulty incorporating multiple "if" statements into my code

I'm currently working on creating an IE9 specific if statement. Basically, I want to check if the menu is collapsed and then move 3 classes from the left if it is true, or in the opposite direction if it is false. However, I'm struggling to get t ...

How can I optimize my .find query for a MongoDB GET request to achieve maximum performance?

I'm struggling to figure out how to retrieve only the last item stored in my database using a GET request. While I can successfully get the desired output in the mongo shell (as shown below), I haven't been able to replicate it in my GET route qu ...

php utilizing javascript to generate encrypted data for a hidden file

Within my MVC application, I have implemented Raty for rating images. Below is the code snippet: <div class="container"> <form method="post" class='form' role='form' action="?section=photo&view=addVote"> <input t ...

An error occurred at line 120 in the index.js file of the http-proxy library: "socket hang up"

I encountered an issue while running expressJS in one of the containers within docker-compose. When I repeatedly refresh the landing page by pressing CMD+R (approximately every 3-4 seconds), it displays an error message "Error: socket hang up" causing the ...

Accessing information from a JSON array

I am encountering difficulties in fetching data from a JSON file. Whenever I click the button, it triggers the call function which then retrieves data from the json.jsp file containing an array. However, I am unable to retrieve the data successfully. Below ...

Display fixed information in a separate tab using express and ejs

I have an Express app that is running smoothly with a MongoDB backend, and it's able to render tables with data flawlessly. However, I've encountered an issue when trying to export a table from my database. The exported table looks something like ...

Passing Data from Child to Parent Components in ReactJS

I'm new to React and JavaScript, currently working on a website. I've encountered an issue with passing data between components from child to parent. Here's the scenario: In my App.js script, I'm using react-router-dom for routing. I ...

What is the best way to pass information between Express middleware and endpoints?

Many middleware packages come with factories that accept an options object, which often includes a function to provide necessary information to the middleware. One example of this is express-preconditions: app.use(preconditions({ stateAsync: async (re ...

What is the process for retrieving the text element from a React component when using React.cloneElement?

Can I centralize a translation function for all table header elements? const CustomersTable = () => { var headers=<> <th>Name</th> <th>Age</th> <th>Another text</th> </> ...

Harvesting the local image file

Currently, I have implemented a form that allows users to upload images and crop them. The process flow has been established as follows: 1. User uploads the image 2. Server processes the image and sends it back to the browser 3. User crops the image a ...

Guide on implementing image tag and source in Django template language system

I need to include a base64 encoded image in JSON format into a Django HTML template. What is the best way to do this? <img src="R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp(Some 64 bit image);base64 /> How can I properly translate this code snippet into my ...

Transforming every piece of TypeScript code into JavaScript on the server-side

I'm relatively new to developing Node.js applications for production. I've created an app using TypeScript for the backend of my Node.js project. Currently, in the package.json file, I have the following script section: "scripts": { ...

Employing Modernizer.js to automatically redirect users to a compatible page if drag and drop functionality is not supported

I recently set up modernizer.js to check if a page supports drag and drop functionality. Initially, I had it set up so that one div would display if drag and drop was supported, and another div would show if it wasn't. However, I ran into issues with ...

Remove the option to select specific minutes from the time input on an HTML

My HTML code includes a time input that looks like this: <input id="appt-time" type="time" name="appt-time" value="13:30" /> I want to figure out how I can remove the minutes from the input or ensure that the ...

Toggle Jquery feature will dynamically add the "required" attribute to the input field when the specified div is visible, and it will automatically remove the attribute when the div

I am new to using jQuery and I am facing an issue with my code. I want to make a checkbox act as a toggle with jQuery. When the checkbox is clicked and the toggle displays the div, I want to add the required attribute to the checkbox input. Similarly, when ...

DevExpress popup remains contained within the iframe and does not overflow beyond its boundaries

My dilemma involves incorporating a FilterControl within an iframe popup. My issue arises when using the column selector (or any other DevExpress combobox), as the popup remains confined within the frame without extending beyond its borders. I am seeking a ...

Comparing Selenium and Watir for JavaScript Testing within a Rails environment

In our experience with Rails apps, we have found success using RSpec and Cucumber. While Webrat is effective for non-AJAX interactions, we are now gearing up to write tests for our Javascript. We have used Selenium support in Webrat before, but I am inter ...

A step-by-step guide on how to implement a window scroll-controlled color transition

I've implemented jQuery code to change the opacity of my navbar's background as the user scrolls, transitioning from transparent to blue. Here's the snippet: $(window).scroll(function(){ var range = $(this).scrollTop(); var limit = 45 ...