We help IT Professionals succeed at work.

detect numeric form using java script

chengxi
chengxi asked
on
how can i detect and determined whether a value is numeric or not using java script?? plz provide a sample code T Q.

One more question is that possble that i use both java and vb script in the same asp page??
Comment
Watch Question

Commented:
In javascript: it is isNaN("value")

<form>
<input type=text name="myfield">
<input type=button value="is it numeric?" onClick="alert(!isNaN(this.form.myfield.value)">
</form>

In VB and VBS it is IsNumeric("value")

And yes you can use VBScript and Javascript on the same page. Clientside VB and clientside Javascript I mean...

regards,
CJ
CERTIFIED EXPERT
Top Expert 2005

Commented:
You can even use VBScript client side if you want to limit yourself to MS Explorer; just be careful not to try to write server-side type code and then expect it to work on the client side.

If you are working with numbers, you might also want to look at parseFloat(strToConvert). This will ensure that any string of characters that look like numbers will behave that way:

strItem1 ="123"
strItem2 = "456"

strItem1 + strItem2 returns 123456


parseFloat(strItem1) + parseFloat(strItem2) returns 579

Author

Commented:
thank you for your answer dude....

:-)

Author

Commented:
i assume this will work CJ_S.... because im not the one who need it how ever if there is a problem i will post it to you to get help....

hope you dont mind...

Commented:
Sure, I jst hope that email notifications are working again :-/

Explore More ContentExplore courses, solutions, and other research materials related to this topic.