0

What I want it once I get going through my form, ansering all my question and hit calculate, I want to be able to see the results as $1234 instead of just 1234. Is there a way to do that.

Also I might want to show it like this Your total cost is: $1234(based on submitted data) then a button like ADD to profile. Please help! Thank you in advance!

Script:

<script>function calculate() {
var total = (parseInt($('#studenttut option:selected').val()) + parseInt($('#campusrb>option:selected').val())) * parseInt($('#yearsatten>option:selected').val());
$("#total").text(total);
}
</script>

HTML:

<form>
<div id="1">
<table width="100%">
<tr>
    <td>Are you an In-State-Student?</td>
    <td align="right">
        <select id="studenttut">
            <option value="<?php echo $NIST; ?>">Yes $<?php echo $IST; ?></option>
            <option value="<?php echo $NOST; ?>">No $<?php echo $OST; ?></option>
        </select>
    </td>
</tr>
</table>
</div>

<div id="2">
<table width="100%">
<tr>
    <td>Are you staying on campus?</td>
    <td align="right">
        <select id="campusrb">
            <option value="<?php echo $NBS; ?>">Yes $<?php echo $BS; ?</option>
            <option value="1">No $0</option>
        </select>
    </td>
</tr>
</table>
</div>

<div id="3">
<table width="100%">
<tr>
    <td>How many years are you planning to attend?</td>
    <td align="right">
        <select id="yearsatten">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="2">3</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
            <option value="7">7</option>
            <option value="8">8</option>
        </select>
    </td>
</tr>
</table>
</div>

<div id="4">
<div id="total"><input type="button" onClick="calculate()" value="calculate"/></div>
</form>

</div>
Dallas Clymer
  • 105
  • 1
  • 1
  • 10
  • 1
    Don't use [parseInt without a radix](http://stackoverflow.com/questions/7818903/jslint-says-missing-radix-parameter-what-should-i-do). – Quentin Apr 01 '13 at 08:07

3 Answers3

2

This is just basic string concatenation:

$("#total").text("$" + total);
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • OMG thank you lol, I feel kind of dumb if its that simple, but I guess I'm new to jquery so I'm learning. Thanks for the reference and the quick reply :) – Dallas Clymer Apr 01 '13 at 08:10
1

Just append the $ symbol to the total

var total = (parseInt($('#studenttut option:selected').val()) + parseInt($('#campusrb>option:selected').val())) * parseInt($('#yearsatten>option:selected').val());

var orginal ='$'+total;
$("#total").text(orginal);
Gopesh
  • 3,882
  • 11
  • 37
  • 52
0

You can try this:

<script>
   function calculate() {
     var total = '$' + ((parseInt($('#studenttut option:selected').val()) + parseInt($('#campusrb>option:selected').val())) * parseInt($('#yearsatten>option:selected').val()));
     $("#total").text(total);
   }
</script>

or more easy way:

$("#total").text('$' + total);
Jai
  • 74,255
  • 12
  • 74
  • 103