I'm working on a very simple program that takes a user-specified number (can be an integer or a float of any length) and performs one specific multiplication operation on that number. The program then displays the result of the equation in a separate read-only input field. The output value may be a decimal of any length (I haven't set a step to limit its character length) so the output could be something like "12.1", or it could be something like "259.000003889".
<input type="text" id="inputValue" name="human age" /> <!-- The text area where the user inputs the number value of their choice - NOT the one I want to change the width of. -->
<input type="button" id="submit" name="submit age" value="calculate" onclick="calculateAge()" /> <!-- Button that submits the user-inputted number and activates the calculateAge function. -->
<input type="number" id="outputValue" name="converted age" readonly /> <!-- The text area where the result of the equation is displayed. This is the one whose width I want to change according to its content. -->
<script>
//Simple calculate function that takes the input value by its ID and multiplies it by a static decimal, then sets that end value to be the output value.
function calculateAge() {
let inVal = document.getElementById('inputValue').value;
let outVal = document.getElementById('outputValue').value = inVal * 0.4893
}
let calculate = document.getElementById('submit');
calculate.addEventListener('click', calculateAge());
</script>
The end value is supposed to represent a length of time (it's a fantasy project that converts human age to an equivalent fictional creature age.) Because of this, I have text that says "years" after the number, separate from the input field.
Only problem is, I want the width of the input field to dynamically adjust itself based on the character length of the result number that is displayed in it. (Really just for appearance purposes, so the end result looks more fluid, but it's an important feature to me.) I've tried a few different online tutorials and they haven't worked thus far - not sure why. I don't get error messages, the program continues to work as intended but I get no change to the input field width.
I have no styling or specific fonts set for this program, it's all default font, default sizing, in black-and-white. That is to say, there is no unusual font size/weight/style present that might disturb the width of the text field.
Any suggestions? None of the tutorials I've tried have worked and it's really bugging me - I know it's something I've probably done wrong or forgotten to do, advice would be appreciated!
outputelement instead? That one can easily adapt to the width of its content, with no extra scripting.