|
This 18 message thread spans 2 pages: < < 1 [2]
|
|
You can use string concatenation, which is just the plus sign. "$" + 0.45, should result in a string "$0.45". JavaScript will automatically cast to the right type.
|
|
|
|
|
So, where do I put that in my code? Should it look like this:?
</script>
<script type="text/javascript">
function myCalc()
{
var t00 = document.getElementById("YesNo");
var t01 = document.getElementById("txt01");
var t02 = document.getElementById("txt02");
var t03 = document.getElementById("txt03");
var t04 = document.getElementById("txt04");
if ( (isNaN(t01.value) == true) || (isNaN(t02.value) == true))
{
t03.value = 0;
t04.value = 0;
return
}
if (t00.value == "1")
{
t03.value = "$" + t01.value - "$" + t02.value;
t04.value = "$" + t01.value - "$" + t02.value;
}
else
{
t03.value = ("$" + t01.value - "$" + t02.value) * 0.85;
t04.value = "$" + t01.value - "$" + t02.value;
}
}
</script>
|
|
|
No, I don't think that will work.
You need to "tack on" the dollar sign at the last step.
So where you have:
t04.value = "$" + t01.value - "$" + t02.value;
Instead use a variable:
var myNewValue = t01.value - t02.value;
t04.value = "$" + X;
A construction like that should work.
An added complication though. If your users re-enter values to recalculate, you'll have to check for and strip out the dollar signs before you do your calculation.
But we'll save that for later. First let's get the dollar sign in there, then we'll work on getting it back out, if needed.
Try rewriting your function with the suggestions in this message, and let me know how things go.
|
|
|
|
This 18 message thread spans 2 pages: < < 1 [2] |
|
|
|
|
// |