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  > >  
  Need assistance....  cwilkey at 15:33 on Tuesday, December 14, 2004
 

I have the following code:
<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 (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>

Currently if alphanumeric characters are entered the calculation displays a NaN. In the event alpa numberic characters are entered I would like it to display "0" instead of NaN. Is that possible?

  Re: Need assistance....  tgreer at 18:32 on Tuesday, December 14, 2004
 

Sure, use the "isNaN()" function. So test your result, if isNaN returns true, then assign "0" to your value.



  Re: Need assistance....  cwilkey at 18:44 on Tuesday, December 14, 2004
 

I'm sorry. I'm new to javascript. ASP is my forte. Could you possibly give an example?

  Re: Need assistance....  tgreer at 18:58 on Tuesday, December 14, 2004
 

<html>
<head>
<script type="text/javascript">
function checkN(x)
{
if (isNaN(x.value) == true)
{
x.value = 0;
}
}
</script>
</head>
<body>
<form>
<input type="text" onblur="checkN(this);"/>
</form>

</body>
</html>



  Re: Need assistance....  cwilkey at 19:15 on Tuesday, December 14, 2004
 

Sorry...I guess I need to be a little more descriptive. Here is my current 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 (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>

I want it to where if a user enters an alphanumeric character into txt01 and txt02 then txt03 and txt04 have a value of 0.



  Re: Need assistance....  tgreer at 19:25 on Tuesday, December 14, 2004
 

Hey, this script looks familiar! Try this version:

<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;
}

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>

That will check to see if BOTH t01 and t02 are alphanumeric. If you want to have 3 & 4 to be zero if EITHER 1 or 2 is alpha, change the "&&" to "||".

In English: if the value of t01 AND the value of t02 are both NOT Numeric, then make the value of t03 and t04 zero.

You know the score: if this post was helpful, click Ads! My site is also advertiser supported (hint, hint).


  Re: Need assistance....  cwilkey at 19:38 on Tuesday, December 14, 2004
 

Hmm....

It is still displaying NaN. Click on the following link http://63.174.89.102/QNI/ReconChange/sales_form.asp. There are two form fields, "Change From" and "Change To". Currently, when you put numberic characters in those fields and hit the "Calculate" button a calculation is performed and the results are displayed in the net and gross adjustment fields. Try typing alphanumeric characters in the Change From and Change To fields...then press Calculate. It will display NaN...I want it to display 0.

  Re: Need assistance....  tgreer at 19:51 on Tuesday, December 14, 2004
 

You have multiple script blocks with the myCalc() function. Make sure you edit out the "old" one.

To make my addition work, add "return":


if ( (isNaN(t01.value) == true) || (isNaN(t02.value) == true))
{
t03.value = 0;
t04.value = 0;
return;
}


This will cause the script to abort immediately, setting the values of txt03 and txt04 to 0.

If you don't return, then the script runs and re-calculates t03 and t04.



  Re: Need assistance....  cwilkey at 19:54 on Tuesday, December 14, 2004
 

PERFECT!!!!!

THANK YOU SO MUCH. Is there anything I can do for you?

  Re: Need assistance....  cwilkey at 19:57 on Tuesday, December 14, 2004
 

I went to your website and clicked on about every link I could find. I also see where you are a guitar player. Me too!!

www.cjandthebigbrotherband.com


  Re: Need assistance....  tgreer at 20:02 on Tuesday, December 14, 2004
 

Thanks for clicking the links... of course, it's the ads that pay!

I know it's cheesy to keep mentioning ads, but sites like Codetoad and my own survive on ad revenue.

I'm happy to help! I couldn't get your audio bytes to play, what gives?





  Re: Need assistance....  cwilkey at 20:07 on Tuesday, December 14, 2004
 

Ya just need to be patient. When you click on it you will see that its downloading in the bottom of your browser. They are rather large MP3s so if your on a dial up line...well you'll be waiting for awhile. Otherwise just be patient.

Thanks again.

  Re: Need assistance....  tgreer at 20:10 on Tuesday, December 14, 2004
 

Sounds good! I don't play in a band, but my family is very musical. Acoustic and Electric guitar, mandolin, piano... a good friend of mine and co-worked plays bass and has been in bands for years.


  Re: Need assistance....  cwilkey at 20:13 on Tuesday, December 14, 2004
 

I too come from a very musical family. As you can see from the website, I play with my two older brothers. Our father toured for awhile with a country western band in the 80s. We have an uncle who is fluent on about any stringed instrument made; mandolin, guitar, banjo, etc.

  Re: Need assistance....  cwilkey at 22:46 on Wednesday, January 05, 2005
 

Greetings...

I was hoping that you might be able to further help me on a javascript that you wrote for me. To refresh your memory, please refer to the following code:

<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>
<script type="text/javascript">
function direct()
{
var t00 = document.getElementById("YesNo");
var t05 = document.getElementById("txt05");


if (t00.value == "1")
{
t05.value = "DIRECT";
}
}

</script>

This script works great for me. The only other thing I need is to reflect that these fields will be displaying $ therefore I need everything to be formatted accordingly. ex. $456.45

Make sense?

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
•  Re: Unlink
•  Deleteing files from Directory on unix
•  YV12 viewer
•  alert() statement lets code work, remove it, code errors out
•  updat Date automatic
•  Need javascript help
•  help me
•  How to display a message box when record is temporary stored in session/grid view
•  Re: open excel file in html page


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