Reputation: 215
I am trying to multiply a value that is already generated using jquery, but a static value. I have done this when the value is coming from a text box, just not from a span tag.
The script below works when taking value from a textbox. How can I modify this to read teh
Here is what I have so far:
HTML This is the file that I want to multiply static value by
<p id="sum" name="equip_amount_four"></p>
This is the place I want to place the answer of the static value by the html above
<p>$ <span id="equipPymnt" name="equip_payment"></span></p>
jQuery
<script>
var multiplyShares = function() {
var val1 = parseFloat($('#shares').val())
var val2 = .086667
val3 = val1 * val2 || "Invalid number"
$("#result").html(val3.toFixed(2))
}
$("#shares").keyup(function() { multiplyShares(); });
</script>
Upvotes: 0
Views: 108
Reputation: 10924
It looks like you have a few mismatched IDs in your HTML. The following works:
var multiplyShares = function() {
var val1 = parseFloat($('#sum').text());
var val2 = .086667;
var val3 = val1 * val2;
val3 = isNaN(val3) ? "Invalid number" : val3.toFixed(2);
$("#equipPymnt").html(val3);
}
multiplyShares();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<p id="sum" name="equip_amount_four">500</p>
<p>$ <span id="equipPymnt" name="equip_payment"></span></p>
Upvotes: 1