Having 2 inputs multiply when one acts as a percentage

Hi everyone

I am trying to calculate input 1’s value by input 2’s value, so it results in input 3. The form looks like so

<form action="">
          <h3>Breakeven Analysis</h3>
          Customer Lifetime Value: <br>
          <input value="" type="text"  class='number1'/><br/>
          Gross Margin: <br>
          <input value=""  type="text" class='number2'/><br/>
          Marin Per Customer: <br> 
          <input value=""  type="text" class='number3'/><br/>

i am trying to use jquery to complete this task. This is what I have so far

$('.field1, .field2').change(function(){
  $('.field3').val($('.field1').val() * $('.field2').val() / 100);

Not to sure where to from here. Basically, if input one was 3000, and input 2 60 (%), then input 3 should populate to 1800

but your inputs do not have the classes field1, or field2, or field3 – you’ve used number1, number2 and number3.

Thus, you’d either need to change their class names, or change the script to use .number1, .number2, .number3.

On the one hand, I have this running as a jsFiddle. On the other hand, I am not sure if you want to be GIVEN the answer, or you want to figure it on your own.

1 Like

such an easy fix. thank you. I forgot i changed the classnames and didn’t change them in my script file. Much appreciated!

easy mistake to make. Helps to have fresh eyes. o.O

1 Like