0

I am using the Split function to take a selected option value and split by each pipe delimeter.

The value of exploded[2] is correctly shown as 10.00 when outputted but the finance function does not return a value and my div does not get updated with fresh text.

If I swap exploded[2] to a literal 10.00 within the function like this:

finance(exploded[0], exploded[1], 10.00, exploded[3]); 

it works. Similarly, if I make exploded[2] = 10.00 like this:

var test = 10.00;
finance(exploded[0], exploded[1], test, exploded[3]);

it works too. Have I done something stupid?

The Javascript

<script type="text/javascript">

$(document).ready(function() {

  $('#finance').change(function() {     
    selected_value = $('#finance').val();
    exploded = selected_value.split('|');
    finance(exploded[0], exploded[1], exploded[2], exploded[3]);    
  });

  function finance(code, order_cost, depost_pc, deposit_val) {
    my_fd_obj = new FinanceDetails(code, order_cost, depost_pc, deposit_val);
    $('#finance_per_month').html(my_fd_obj.m_inst);     
  }

  });

</script>

The HTML

<select name='finance' id='finance'>
  <option value="ONIF10|399.00|10.00|39.90">10 Months 0% Finance</option>
  <option value="ONIF18|399.00|10.00|39.90">18 Months 0% Finance</option>
  <option value="ONIF24|399.00|10.00|39.90">24 Months 0% Finance</option>
  <option value="ISIB36-3.9|399.00|10.00|39.90">36 Months 3.9% Finance</option>
</select>
1
  • split is working for sure, probably the issue can be found from FinanceDetails(). Also it would be easier to pass the whole array instead of a bunch of arguments. Also you say: "... the finance function does not return a value ...", Obviously it doesn't , there's no return something in the said function, and actually there's no receiver for the return value either in the posted code. Commented Apr 26, 2014 at 16:57

1 Answer 1

1

Impossible to say for sure without knowing more about FinanceDetails, but the difference between exploded[2] and 10.00 is that the former is a string ("10.00", not 10.00). 99% of the time, code will implicitly coerce strings to numbers, but again not knowing what's in FinanceDetails...

parseFloat(exploded[2]) might solve the problem. Or just +exploded[2].

I'd expect you would need to do this for the other args as well, if they're also meant to be numbers.

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

2 Comments

@monkey64: LOL You just did. :-)
@T.J.Crowder Sometimes I feel sure you've a chrystal ball ; ).

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.