0

I was wondering how you can resize text size in javascript based off of user input. Say for example, if the input exceeds 1000000000, then set text size to 14. The userinput in this case would be the Price and the size I would like to modify is the the TotalAmount and TipAmount.

3
  • element.style["font-size"] inside of a switch statement Commented Apr 22, 2018 at 19:11
  • I am not familiar with a switch statement but thank you for taking your time to respond Commented Apr 22, 2018 at 19:14
  • 2
    Please provide code of what you already tried and give a little more context. Commented Apr 22, 2018 at 19:16

3 Answers 3

2

Like this?

function changeTextSize() {
  var input = document.getElementById('input').value;
  
  document.getElementById('text').style.fontSize = input + "px";
}
<p id="text">I am some text.</p>
<input type="text" onkeyup="changeTextSize()" id="input">


Or like this?

function changeTextSize() {
  var input = document.getElementById('input').value;

  if (input > 1000) {
    document.getElementById('text').style.fontSize = 30 + "px"; // Changed 14 to 30, because 14 would be smaller than the default text size
  }
}
<p id="text">I am some Text</p>
<input type="text" onkeyup="changeTextSize()" id="input">

Sign up to request clarification or add additional context in comments.

Comments

1

Is that what you are looking for?

var priceInput = document.getElementById('price-input');
priceInput.addEventListener('input', function(e) {
  var price = parseInt(e.target.value);
  priceInput.style.fontSize = price > 10 ? "14px" : "10px";
});
<input id="price-input" />

Comments

0

You may apply styles with JS.

Given that input and outputs are strings:

if(price > 10000){outputElement.style.fontSize = "0.8em"}

2 Comments

14 is not a valid font-size value, developer.mozilla.org/en-US/docs/Web/CSS/font-size
Updating now :-) Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.