codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
This 18 message thread spans 2 pages:  < <   1  [2] 
  Re: Need assistance....  tgreer at 23:27 on Wednesday, January 05, 2005
 

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.



  Re: Need assistance....  cwilkey at 14:10 on Thursday, January 06, 2005
 

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>


  Re: Need assistance....  tgreer at 15:09 on Thursday, January 06, 2005
 

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] 







CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Calcluate Date Difference [Seriouslt a new challenge]
•  source code to generate perl library
•  Plz Help Me Out...!!! I want to add a crystal report to my application
•  Floating div
•  Re: open excel file in html page
•  Such A Newbie - Mailing Label Program
•  Classified Script
•  Re: saving??
•  Re: Date script issues


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007