Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How to ........... in Javascript?

Hi All

There are 2 things that I need to do in Javascript buit don't really know
how? Hope you guys out there can help. They are:-

1) How to I determine whether a string entered is purely numeric or otherwise?
In Javascript, is there any function such as IsNumeric()?

2) I need to do something like this - when a user press a button say browse,
a dialogbox or something of the sort would appear with all the directory
structure of the PC or Server and I just have to click on the directory structure
to get the directory path value which I can set to a variable inside my HTML/ASP
script. Wonder ifthere are any ActiveX control or ways of how this can be
achieved!

Pls Help!!!!

rgds,
Saiful
[772 byte] By [saiful] at [2007-11-9 15:36:13]
# 1 Re: How to ........... in Javascript?
[snip]
> 1) How to I determine whether a string entered is purely numeric or
otherwise?
> In Javascript, is there any function such as IsNumeric()?

the parseInt and parseFloat functions take a variable in, attempt to extract
an int or float respectively and return NaN if the value entered is, you
guessed it, not a number..

var x = 'aby635';
if isNaN(parseInt(x)) {
// it's not a number
}else{
...
}

> 2) I need to do something like this - when a user press a button say
browse,
> a dialogbox or something of the sort would appear with all the directory
> structure of the PC or Server and I just have to click on the directory
structure
> to get the directory path value which I can set to a variable inside my
HTML/ASP
> script. Wonder ifthere are any ActiveX control or ways of how this can be
> achieved!

well, you're on your own on that one. If you want to give back dir lists of
the server,
you can use the FileSystemObject's API. If you ant to browse the client's
fs, you're screwed.

> Pls Help!!!!
>
>
> rgds,
> Saiful
>
Ryan Tomayko at 2007-11-11 23:41:11 >
# 2 Re: How to ........... in Javascript?
Ryan Tomayko wrote in message <3977a247@news.dev-archive.com>...
>[snip]
>> 1) How to I determine whether a string entered is purely numeric or
>otherwise?
>> In Javascript, is there any function such as IsNumeric()?
>
>the parseInt and parseFloat functions take a variable in, attempt to
extract
>an int or float respectively and return NaN if the value entered is, you
>guessed it, not a number..
>
>var x = 'aby635';
>if isNaN(parseInt(x)) {
> // it's not a number
>}else{
> ...
>}

[...]

Fortunately, or unfortunately, parseInt will successfully return a number if
a string of digits and alphas begin with at least one digit:

var x = '1a3a4afr6';
var y = parseInt(x); <-- y now = 1

if isNaN(parseInt(x) <-- false

BettyB.
BettyB at 2007-11-11 23:42:11 >