Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java If Statement

Status
Not open for further replies.

aumstu

MIS
Jan 20, 2006
40
US
I posted this message earlier but was unable to log back in b/c of a registration problem. Not sure exactly what happened there. But I noticed that dotnet had responded but I was unable to view the response. So here it goes again…


I have some java script code that alerts the user if the did not enter a numeric value in the textbox. Underneath that I have the calculations that would determine the answer…

Like textbox1 = 10
Textbox2 = 10

Code textbox1/textbox2 = 10

Right now it will go through the code and if textbox1 is not a number…then the value for the calculations is NaN. Is there a way I can put a If statement using javascript around the calculations that states…if textbox1 and textbox2 is a number then compute else do nothing.


Thanks for any help
 


a) Java is NOT the same as Javascript
b) Javascript is NOT the same as ASP
c) This is the ASP forum
d) Javascript forum is forum216



A smile is worth a thousand kind words. So smile, it's easy! :)
 
I think you're looking for how to construct an if statement in javascript? If so, here's how I do it.

<script LANGUAGE="JavaScript">
function checkCalc(){
var txt1 = new Number(document.Form1.textbox1.value);
var txt2 = new Number(document.Form1.textbox2.value);
if ((isNaN(txt1)) || (isNaN(txt2)))
{
alert ("textbox1 and textbox2 must be a valid numbers");
return false;
}

else
{ var myNum = new Number();
myNum = (txt1 / txt2)
alert (myNum);
return true;
}
}
</script>
 
jrenae
Welcome to Tek-Tips. Your helpful answers will make you a valued member of these forums. Have a look at faq222-2244 to see how the forums work. That way we can hopefully keep Javascript questions in the Javascript forum, and ASP stuff in the ASP forum. Makes life a lot easier for members searching for info if it's in it's expected forum.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
johnwm - OK...thanks...in the future I will not reply if a question is in the wrong forum. By the way...love this site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top