0

I have the following code.

<select id="cage_options"> <option>Please select</option> <option value="2,63330">option1</option> <option value="3,13300">option2</option> <option value="4,2000.00">option3</option> </select> <input id="cage_labor_estimate" disabled> <script> function format(n) { return n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,"); } document.getElementById("cage_options").addEventListener("change", cageOptionFunction); function cageOptionFunction() { select=document.getElementById('cage_options').value.split(','); cage_option = select[1]; document.getElementById("cage_labor_estimate").value = format(cage_option); } </script> 

I am trying to format the output in the disabled input box in a current format but get the following error:

TypeError: n.toFixed is not a function. (In 'n.toFixed(2)', 'n.toFixed' is undefined)

Can anyone help?

Thanks,

John

1
  • because you have a string, not a number. Commented Sep 22, 2016 at 11:05

1 Answer 1

3

You have a string and a string does not have .toFixed(). So need to convert that string to be a number.

cage_option = Number(select[1]); 

or

cage_option = parseFloat(select[1]); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.