JavaScript how can I show confirmation of what text was entered as input?

I am a student and very new to JS, like this is my first project dealing with it. With that being said, please excuse how juvenile my coding may seem to you experts. I followed the instructions of my project...

I am trying to figure out how to show a confirm of what the user types in the input. I have read through the similar previous questions but none of them are as basic as my coding so I do not know how to follow those examples to correct my issue.

Also, I cannot figure out why my total is combining the numbers side by side instead of adding them together. I have tried many different variations of these operations but cannot figure out what I am doing wrong.

Can someone help me figure out how to show what the user entered and how to add the cost and tax for a total vs them combining? Any help is appreciated.

var tileLetters;
var cost = 3;
var taxes = 0.08;

function confirmEntry() {
  tileLetters= document.getElementById("letters").text; document.getElementById("confirm").innerHTML= tileLetters;
}

function calculateCost() {
  tileLetters = document.getElementById("letters").value;
  var tileCount= tileLetters.length;
  var spaceCount= (tileLetters.split(" ").length - 1);
  var tax= (tileCount - spaceCount) * cost;
 
 document.getElementById("cost").innerHTML= "Subtotal $" + (tileCount - spaceCount) * cost; 
  
 document.getElementById("taxes").innerHTML= "Plus taxes $" + (tileCount - spaceCount) * cost * taxes;
 
 document.getElementById("total").innerHTML= "Your total cost is $" + (tileCount - spaceCount) * cost * taxes + ((tileCount - spaceCount) * cost);  
}
<input id="letters" type="text" name="entry"><br>
	
	<button onclick="confirmEntry() + calculateCost()">Calculate Your Cost</button>
	
  <p id="confirm">You entered</p>
  <p id="cost">Cost</p>
	<p id="taxes">plus taxes</p>
  <p id="total">Total cost</p>
Answer:1

An input box doesn't have a property called .text. You probably wanted .value:

tileLetters = document.getElementById("letters").value;

Your code is adding the numbers onto the end rather than mathematically adding them because it is treating this as a string concatenation rather than a numeric operation (e.g. think what happens when you do "Hello" + " World" - it gives you "Hello World"). To get it to behave how you want; you need to ensure that both things you are adding are numbers.

One way to do this is the parseFloat function. This takes a string, and converts it to a floating point number; e.g. parseFloat("6") gives you 6.0 rather than the "6" you had before.

Answer:2

first of, in order to get the value from input you need to do this:

function confirmEntry() {
  tileLetters= document.getElementById("letters").value;// value not text 
document.getElementById("confirm").innerHTML= tileLetters;
}

secound it will not work all the time since you can add letters to numbers. so you can check if its a number maybe with simple js function isNaN(). check out this

Answer:3

You are doing some mistakes in your HTML. This is what you're looking for:

1. How to get the value of an input box

To get the value of an input box, you reference it by .value. Example:

function calculate() {
     var valueOfInputBox = document.getElementById("input-box").value;
     document.getElementById("result").innerHTML = valueOfInputBox;
}
<input id="input-box" type="text">
<button onclick="calculate()">Submit</button><br>
Result: <a id="result"></a>
Answer:4

I'm trying to iterate over a simple array using recursion. For this specific case, I'm trying to recreate .map() using recursion (without using .map()!. I currently am only pushing the last element ...

I'm trying to iterate over a simple array using recursion. For this specific case, I'm trying to recreate .map() using recursion (without using .map()!. I currently am only pushing the last element ...

  1. two dimensional array iteration in java
  2. 2 dimensional array iteration
  3. two dimensional array iteration
  4. javascript two dimensional array iteration
  5. c# two dimensional array iteration
  6. php multidimensional array iteration

Consider a matrix B= [[6,4,1,2], [5,3,9,7],[1,3,2,1]];. B is a matrix with three rows and four columns. I want to treat it as an array or a vector, namely B1=[6,4,1,2,5,3,9,7,1,3,2,1]. Moreover, I ...

Consider a matrix B= [[6,4,1,2], [5,3,9,7],[1,3,2,1]];. B is a matrix with three rows and four columns. I want to treat it as an array or a vector, namely B1=[6,4,1,2,5,3,9,7,1,3,2,1]. Moreover, I ...

  1. transform matrix into vector matlab
  2. transform matrix into dataframe r
  3. transform matrix into diagonal form
  4. transform matrix into upper triangular form
  5. transform matrix into vector
  6. transform matrix into jordan canonical form
  7. transform matrix into vector r
  8. transform matrix into column excel
  9. transform matrix into reduced echelon form
  10. transform matrix into row echelon form
  11. transform matrix into vector python
  12. transform matrix into positive definite
  13. transform matrix into dataframe
  14. transform matrix into vector excel
  15. transform matrix into dataframe python
  16. transform matrix into table matlab
  17. transform matrix into list python
  18. transform matrix into list
  19. transform matrix into upper triangular
  20. transform matrix in css

I have some code running in an html page that is calling a function that exists on window.external. The code works: SomeCode.js (lives in somePage.html): window.external['someFunction'](); However, ...

I have some code running in an html page that is calling a function that exists on window.external. The code works: SomeCode.js (lives in somePage.html): window.external['someFunction'](); However, ...

  1. setting iframe height to match content height
  2. setting iframe size
  3. setting iframe width and height
  4. setting iframe src in jquery
  5. setting iframe height dynamically
  6. setting iframe src in javascript
  7. setting iframe height
  8. setting iframe source with javascript
  9. setting iframe content dynamically
  10. setting iframe height to auto
  11. setting iframe content
  12. setting iframe width
  13. setting iframe height dynamically using jquery
  14. setting iframe border
  15. setting iframe dimensions
  16. setting iframe innerhtml
  17. setting iframe height in css
  18. iframe setting
  19. iframe setting cookie
  20. iframe setting in chrome

So in sql a common thing to do is a select statement with a group by and then a having count =1 or what have you. select bID from tableA groubBy bID having count(*) = 1 Essentially I am looking to ...

So in sql a common thing to do is a select statement with a group by and then a having count =1 or what have you. select bID from tableA groubBy bID having count(*) = 1 Essentially I am looking to ...