Attempting to utilize the data inputted into number field1 to be shown in a read-only div2

I have a task of converting a Google Sheets document that gathers various data inputs from users and performs multiple calculations. My goal is to transform it into a webpage connected to an SQL database.

To manipulate the calculable data on the webpage, I am utilizing jquery, and my knowledge of SQL is solid.

While I worked with Javascript in the past, it has been a while, and I could use a refresher.

I have set up a table with 5 rows for capturing the square footage (SF) of three different types of spaces.

Space Type involves a drop-down menu,
Floor Area is an <input> number field for user input,
% Area is calculated as (Floor Area ÷ Total Area).

If the field requires a numeric value, should I use

 $("#floor-area-1").val()/$("#total-area").val()
?

Could employing .text() be a viable option as suggested by someone?

I intend to populate the innerHTML of DIV elements with the calculation results, e.g.,

 $("#floor-area-1").val()/$("#total-area").val()
.

The remaining sections consist of DIVs where the respective calculations will be displayed in their designated columns.

<!-- Row 1 -->
<div class="div-table-row">
  <div class="div-table-col"  style="width:15%;">
    <select id="space-type-1" name="space-type-1">
      <option value="Education"> Education </option>
      <option value="Food sales"> Food sales </option>
      <option value="Food service"> Food service </option>
      <option value="Health care"> Health care </option>
      <option value="Inpatient"> Inpatient </option>
      <option value="Outpatient"> Outpatient </option>
      <option value="Lodging"> Lodging </option>
      <option value="Mercantile"> Mercantile </option>
      <option value="Retail-1"> Retail <span style="font-size:8px;">(no mall)</span> </option>
      <option value="Retail-2"> Retail <span style="font-size:8px;">(malls)</span> </option>
      <option value="Office"> Office </option>
      <option value="Public assembly"> Public assembly </option>
      <option value="Public safety"> Public safety </option>
      <option value="Religious worship"> Religious worship </option>
      <option value="Service"> Service </option>
      <option value="Storage"> Storage </option>
      <option value="Warehouse"> Warehouse </option>
      <option value="Other"> Other </option>
      <option value="Vacant"> Vacant </option>
    </select>
  </div>
  <div class="div-table-col div-table-col-disp"  style="width:13%;">
    <input class="input-floor-area" type="number" name="floor-area-1" size="13">
  </div> 
  <div id="kwh-used" class="div-table-col div-table-col-calc"
     style="width:10%;border-right-color: #000;">
  </div>
  <div id="kwh-cost" class="div-table-col div-table-col-calc"  style="width:15%;border-right-color: #000;">
  </div>
</div>

% Area represents the floor area percentage of the respective space displayed in that row's cell.

kWh Used takes a value associated with a particular Space Type and multiplies it by the Floor Area, for example, Office = 21 kWh x 20,000 SF will result in 420,000 kWh used appearing in the column under kWh Used in row 1.

In the past, I have utilized document.getElementById(). However, working with jquery syntax may be somewhat different. If anyone knows of any online resources showcasing examples, please direct me towards them, and I believe I can navigate my way through this challenge.

My primary query is how do I capture the text in Space Type and Floor Area and display the results of %Area? Once I comprehend this step, I feel confident about tackling the subsequent tasks.

-----------+------------+--------+----------+----------
Space Type | Floor Area | % Area | kWh Used | kWh Cost 
-----------+------------+--------+----------+----------
Office     |  20,000    |   12%  |   50,000 |  $5,000  
-----------+------------+--------+----------+----------
Hotel      |  150,000   |   87%  |  120,000 | $12,000
-----------+------------+--------+----------+----------
Retail     |  2,000     |    1%  |   19,000 |  $1,900
-----------+------------+--------+----------+----------
Total                   |  100%  |  241,000 | $18,900
-----------+------------+--------+----------+----------


Testing the following code isn't triggering the alert() function.<br>

$( "#floor-area-1" ).on( "blur", function() {
   alert( "Handler for `blur` called." );
} );

Answer №1

Since no code has been provided, I can offer a simple method to help you out. If all you're looking to do is capture the text within div elements, you can utilize .text() in jQuery for both retrieval and modification. You should be able to extract the text, perform your calculations, and then apply any necessary changes.

Check out this link for more information on using .text() in jQuery.

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

What can be done to resolve the issue with the startDate on the datepicker not functioning properly?

<html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap 4 DatePicker</title> <script src="https://c ...

Differences in the way websites scroll on Chrome compared to Safari and Firefox

Currently, I am in the process of developing a rendering system for my application that extracts objects from a collection and processes them through JavaScript templates to generate additional children as the user scrolls through the page. The system is d ...

What steps are involved in enabling Server Side Rendering with Next.js?

For my exploration of Next.js, I started by setting up a new Next.js project and incorporating code to retrieve weather data: export default function Home() { const [data, setData] = useState(null); useEffect(() => { fetch("https://api.we ...

Software communicating with the internet

What programming knowledge do I need to have in order to interact with the web using C++? For example, I want to create a program that automates sending invites to players on Yahoo Chess. How should I approach this task? ...

Vue is refusing to display information for a certain API call

Within my next component, I have the following structure: <template> <div class="home"> <div class="container" v-if="data" > <Card v-for="result in data" :img="result.links[0]&q ...

Is there a way to retrieve the intersection point (Vector3) of the intersectObjects?

I need assistance in finding the point where a ray cast from 'child' intersects with a mesh (child2) using Raycaster: var raycaster = new THREE.Raycaster(); var meshList = []; meshList.push(child2); for (var i = 0; i < child.geometry.vertices ...

Fading in and out numerous DIVs with the magic touch of jQuery

Can you lend a hand with my jQuery dilemma? My brain is fried just thinking about it. This is the structure I'm dealing with: <div id="trigger-1">Trigger 1</div> <div id="trigger-2">Trigger 2</div> <div id="trigger-3">T ...

Ways to determine if the initial character does not have a hyphen

I am attempting to identify when the first letter is not a hyphen in order to add an element at the beginning. Below is the code I have tried: $('.post-category-label .item:first-letter(:not(:contains("-")))').insertBefore('<span class=" ...

What is preventing me from adjusting the padding of the mat-button?

Trying to adjust the default padding of a mat-button, but encountering issues with changing the component's style. Any suggestions on how to subscribe to the default padding (16px)? I've attempted modifying CSS properties to set the padding of a ...

What is the best way to delete the "Click to sort Ascending" text from the header of each column in a bootstrap-vue table?

Recently, I came across a bootstrap-vue table that caught my attention: https://i.sstatic.net/5jENs.png Below is the code snippet for the table setup: <template> <div class="container"> <h1 class="pt-2 pb-3">Bo ...

Is there a way to reverse the image without physically clicking on it?

I've created a JavaScript code for matching images in a 4x4 grid. The goal is to flip the images when clicked and then flip them back if they don't match. I've managed to flip the images initially, but there's an issue with flipping the ...

Unable to assign value to Ref data property in Vue3 due to undefined item

Recently, I've been utilizing Vue3 and Nuxt3 to work on a project. My main task involves extracting the :id parameter from the URL and checking if it matches an ID in a JSON file. If there is a match, I update a reference data point called 'exist ...

Performing JavaScript functions after fetching an XSLT page via AJAX

Is there a way to trigger JavaScript at a particular time without relying on setInterval() or onClick()? The issue I'm facing is that when I click to load an XSLT page using Ajax, the JavaScript within it does not execute even though it's writt ...

What is the xui equivalent of jquery's slideUp/slideDown function?

Hello, I am experimenting with creating a similar effect to jQuery's slideUp and slideDown function using [xui](http://xuijs.com). So far, I have successfully implemented the fade effect: xui.extend({ fadeOut:function(dur, callback) { ...

What is the best way to present both paragraphs and images from a div in a sequential order

Currently, I am developing a compact web tool to assist editors in creating content by utilizing buttons to insert paragraphs and images. The elements are saved with an ID (beginning at 0 and increasing for each new element) and can be previewed in a div n ...

Extracting text from HTML response and implementing a condition in Node.js

Hello, I am a beginner when it comes to node js and haven't had much experience with it before. I could really use some assistance in resolving an issue that I am facing. Below is the code snippet that I am working with: async function reserved_slot(p ...

Exporting multiple modules in next.config.js allows for greater flexibility and customization

I am looking to include multiple modules in my next.config.js file. Currently, my file looks like this: const withImages = require('next-images') const path = require('path') module.exports = withImages({ esModule: false, }); Now ...

Adjusting the dimensions of the geocoder control in Leaflet.js

I need assistance adjusting the size of the geocoder control on my customized map: L.Control.geocoder().addTo(Map) https://i.sstatic.net/UxkQZ.png ...

Methods for updating the value of a `<select>` element in an AngularJS controller

Within my HTML code, I have a select element with options ranging from 1 to 10: <select id="selVal" ng-model="product.quantity" ng-options="o as o for o in quantityValues" ng-change="updateDelta(product.quantity, {{product.quantity}}, product.selec ...

I'm currently working on validating a registration form using the jqueryValidation engine plugin, and encountering issues with certain validations not functioning as expected

My experience with PHP is still new, and I'm currently exploring how to validate a signup form using the jqueryValidation engine plugin. While I managed to validate some aspects successfully, I've hit a roadblock with the user name validation par ...