tags:

views:

66

answers:

1

I need to have a simple calculator that you just change one number and it multiples the value but a number

i.e. if you switch the number from 1 to 3 the below happens. the value can be a text box and the others can be labels

number to buy   1   
    $175.00 YR 1
    $187.50 YR 2
    $212.50 YR 3
    $225.00 YR 4
    $237.50 YR 5



number to buy   3   
    $525.00 YR 1
    $562.50 YR 2
    $637.50 YR 3
    $675.00 YR 4
    $712.50 YR 5
+3  A: 

http://jsfiddle.net/gL2kY/ I made some codes here....

cheers!

(be back in an hour, I need a break.)

jQuery

$('p span').each(function(){
    $(this).data('factor',$(this).text());
});
$('#factor').keyup(function(){
    var factor = this.value;
    $('p span').each(function(){
        $(this).text(function(){
            return $(this).data('factor') * factor;
        });
    });
});

html

<span>number to buy</span>
<input type="text" value="1" id="factor" />   
<p>    $<span>175.00</span> YR 1 </p>
<p>    $<span>187.50</span> YR 2</p>
<p>    $<span>212.50</span> YR 3</p>
<p>    $<span>225.00</span> YR 4</p>
<p>    $<span>237.50</span> YR 5</p>​
Reigel