I'm trying to make the total change based on the search criteria that I have on the FORM AREA. However, for some reason it doesn't parse the string into an array and the total is not displayed properly it has something like e+88 at the end. Totally a newbie at this.
$('.btn-primary').click(function() {
var month = $('#inputMonth').val(); // get option value for month
if (month == 'none') month = '';
var year = $('#inputYear').val(); // get option value for year
if (year == 'none') year = '';
var arr = [];
var totalPrice = 0;
var price;
// problematic part
$('figure.col-sm-3').has('tr:last-child>td:last-child:contains(' + year + ')').has('tr:last-child>td:last-child:contains(' + month + ')').each(function () {
arr.push($('tr.price td:nth-child(even)').text()); // adds each element to array 'arr'
price = $('tr.price td:nth-child(even)').text();
totalPrice += Number(price); // parse into an Integer then do the adding
document.getElementById("displayTotal").innerHTML = "Total amount is currently at <b>"+totalPrice+ "</b> PHP."; // problematic part.
});
// this snippet works fine
$('figure.col-sm-3')
.hide() // hide all of them, and then show if both `has` are true
.has('tr:last-child>td:last-child:contains(' + year + ')')
.has('tr:last-child>td:last-child:contains(' + month + ')')
.show();
return false; // to avoid that button submits the form
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="container">
<div class="row">
<!-- FORM AREA -->
<p id="displayTotal"></p> <!-- display the total here -->
<p>Show items by:</p>
<form class="form-horizontal">
<div class="form-group">
<label for="inputMonth" class="col-sm-2 control-label">Select Month</label>
<div class="col-sm-10">
<select class="form-control" id="inputMonth">
<option value="none"> - </option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputYear" class="col-sm-2 control-label">Select Year</label>
<div class="col-sm-10">
<select class="form-control" id="inputYear">
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-primary">Show results</button>
</div>
</div>
</form>
</div>
</section>
<section class="container">
<div class="row"> <!-- FIRST SET OF ITEMS -->
<figure class="col-sm-3 thumbnail">
<h6 class="text-center text-uppercase">Item 1</h6>
<img src="img1.jpg" />
<table class="table">
<tr class="price">
<td>Price</td>
<td>250</td>
</tr>
<tr>
<td>Condition</td>
<td>new</td>
</tr>
<tr>
<td>Size</td>
<td>36</td>
</tr>
<tr>
<td>Sold on</td>
<td>November 7, 2014</td>
</tr>
</table>
</figure>
<figure class="col-sm-3 thumbnail">
<h6 class="text-center text-uppercase">Item 2</h6>
<img src="img2.jpg" />
<table class="table">
<tr class="price">
<td>Price</td>
<td>250</td>
</tr>
<tr>
<td>Condition</td>
<td>new</td>
</tr>
<tr>
<td>Size</td>
<td>36</td>
</tr>
<tr>
<td>Sold on</td>
<td>December 2, 2014</td>
</tr>
</table>
</figure>
<figure class="col-sm-3 thumbnail">
<h6 class="text-center text-uppercase">Item 3</h6>
<img src="img3.jpg" />
<table class="table">
<tr class="price">
<td>Price</td>
<td>250</td>
</tr>
<tr>
<td>Condition</td>
<td>new</td>
</tr>
<tr>
<td>Size</td>
<td>L</td>
</tr>
<tr>
<td>Sold on</td>
<td>February 19, 2015</td>
</tr>
</table>
</figure>
<figure class="col-sm-3 thumbnail">
<h6 class="text-center text-uppercase">Item 4</h6>
<img src="img4.jpg" />
<table class="table">
<tr class="price">
<td>Price</td>
<td>250</td>
</tr>
<tr>
<td>Condition</td>
<td>new</td>
</tr>
<tr>
<td>Size</td>
<td>XL</td>
</tr>
<tr>
<td>Sold on</td>
<td>February 19, 2015</td>
</tr>
</table>
</figure>
</div>
</section>
totalPrice += parseFloat(price)