Saturday, 8 June 2013

how do i stop Jquery result is showing up in two different forms?

how do i stop Jquery result is showing up in two different forms?

How do I get two separate results using jquery in these forms? I enter information in the first form and the answer shows up in the second.
Html:
<div class="span12">


  <div class="span4">
    <div class="row-fluid exercise1 one_rep_calc_container">
    <form>
            <div class="span4">Weight<input class="weight" type="number" name="weight" size="2" ></div>
            <div class="span4">Reps<input class="reps" type="number" name="reps" size="2" ></div>
            <div class="span4">OneRepMax<input class="one_rep_max" type="number" Name="oneRepMax" size="2" ></div>

    </form>
    </div>
  </div>

 <div class="span4">
    <div class="row-fluid exercise1 one_rep_calc_container">
    <form>
            <div class="span4">Weight<input class="weight" type="number" name="weight" size="2" ></div>
            <div class="span4">Reps<input class="reps" type="number" name="reps" size="2" ></div>
            <div class="span4">OneRepMax<input class="one_rep_max" type="number" Name="oneRepMax" size="2" ></div>

    </form>
    </div>
  </div>

</div>
the class oneRepMax is the solution form wiyh the results of weight and reps.
jquery:
 $('.one_rep_calc_container .weight, .one_rep_calc_container .reps').change(function(){
    // console.log($(this));
    var weight = parseInt($('.one_rep_calc_container .weight').val(), 10 );
    var reps   = parseInt($('.one_rep_calc_container .reps').val(), 10);

    if(weight > 0 && reps > 0){
    var oneRepMaxVal = ((reps*weight)/30) + weight;
    $('.one_rep_calc_container .one_rep_max').val(oneRepMaxVal);
  }
  else {
    $('.one_rep_calc_container .one_rep_max').val('');
  }

});

$('.one_rep_calc_container .calc_one_rep_button').click(function(){
    var weight = parseInt($('.one_rep_calc_container .weight').val(), 10 );
    var reps   = parseInt($('.one_rep_calc_container .reps').val(), 10);

    var oneRepMaxVal = ((reps*weight)/30) + weight;
    $('.one_rep_calc_container .one_rep_max').val(oneRepMaxVal);
});
So how do I keep the results from the first form of oneRepMax separate from the second one.

No comments:

Post a Comment