Cari di JavaScript 
    JavaScript Manual
Daftar Isi
(Sebelumnya) Debug, deleteResponseHeader, e ...registerCFunction, ssjs_genera ... (Berikutnya)

getOptionValueCount

Returns the number of options selected by the user in a SELECT form element.

Server-side function

Implemented in

LiveWire 1.0

Syntax

getOptionValueCount(name)

Parameters

name
Specified by the NAME attribute of the SELECT tag.

Description

The getOptionValueCount function is a top-level server-side JavaScript function not associated with any object.

Use this function with getOptionValue to process user input from SELECT form elements that allow multiple selections.

Examples

See the example for getOptionValue.

See also

getOptionValue


isNaN

Evaluates an argument to determine if it is not a number.

Core function

Implemented in

Navigator 2.0: Unix only
Navigator 3.0, LiveWire 1.0: all platforms

Syntax

isNaN(testValue)

Parameters

testValue
The value you want to evaluate.

Description

isNaN is a built-in JavaScript function. It is not a method associated with any object, but is part of the language itself.

On platforms that support NaN, the parseFloat and parseInt functions return "NaN" when they evaluate a value that is not a number. isNaN returns true if passed "NaN", and false otherwise.

Examples

The following example evaluates floatValue to determine if it is a number and then calls a procedure accordingly:

floatValue=parseFloat(toFloat)
if (isNaN(floatValue)) {
   notFloat()
} else {
   isFloat()
}

See also

Number.NaN, parseFloat, parseInt


Number

Converts the specified object to a number.

Core function

Implemented in

Navigator 4.0, Netscape Server 3.0

Syntax

Number(obj)

Parameter

obj
An object

Description

When the object is a Date object, Number returns a value in milliseconds measured from 01 January, 1970 UTC (GMT), positive after this date, negative before.

If obj is a string that does not contain a well-formed numeric literal, Number returns NaN.

Example

The following example converts the Date object to a numerical value:

<SCRIPT>
d = new Date ("December 17, 1995 03:24:00"); 
document.write (Number(d) + "<BR>");
</SCRIPT>
This prints "819199440000."

See also

Number


parseFloat

Parses a string argument and returns a floating point number.

Core function

Implemented in

Navigator 2.0: If the first character of the string specified in parseFloat(string) cannot be converted to a number, returns "NaN" on Solaris and Irix and 0 on all other platforms.

Navigator 3.0, LiveWire 1.0: Returns "NaN" on all platforms if the first character of the string specified in parseFloat(string) cannot be converted to a number.

Syntax

parseFloat(string)

Parameters

string
A string that represents the value you want to parse.

Description

The parseFloat function is a built-in JavaScript function.

parseFloat parses its argument, a string, and returns a floating point number. If it encounters a character other than a sign (+ or -), numeral (0-9), a decimal point, or an exponent, then it returns the value up to that point and ignores that character and all succeeding characters.

If the first character cannot be converted to a number, parseFloat returns "NaN".

For arithmetic purposes, the "NaN" value is not a number in any radix. You can call the isNaN function to determine if the result of parseFloat is "NaN". If "NaN" is passed on to arithmetic operations, the operation results will also be "NaN".

Examples

The following examples all return 3.14:

parseFloat("3.14")
parseFloat("314e-2")
parseFloat("0.0314E+2")
var x = "3.14"
parseFloat(x)
The following example returns "NaN":

parseFloat("FF2")

See also

isNaN, parseInt


parseInt

Parses a string argument and returns an integer of the specified radix or base.

Core function

Implemented in

Navigator 2.0: If the first character of the string specified in parseInt(string) cannot be converted to a number, returns "NaN" on Solaris and Irix and 0 on all other platforms.

Navigator 3.0, LiveWire 2.0: Returns "NaN" on all platforms if the first character of the string specified in parseInt(string) cannot be converted to a number.

Syntax

parseInt(string,radix)

Parameters

string
A string that represents the value you want to parse.

radix
(Optional) An integer that represents the radix of the return value.

Description

The parseInt function is a built-in JavaScript function.

The parseInt function parses its first argument, a string, and attempts to return an integer of the specified radix (base). For example, a radix of 10 indicates to convert to a decimal number, 8 octal, 16 hexadecimal, and so on. For radixes above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.

If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates numbers to integer values.

If the radix is not specified or is specified as 0, JavaScript assumes the following:

  • If the input string begins with "0x", the radix is 16 (hexadecimal).
  • If the input string begins with "0", the radix is eight (octal).
  • If the input string begins with any other value, the radix is 10 (decimal).
If the first character cannot be converted to a number, parseInt returns "NaN".

For arithmetic purposes, the "NaN" value is not a number in any radix. You can call the isNaN function to determine if the result of parseInt is "NaN". If "NaN" is passed on to arithmetic operations, the operation results will also be "NaN".

Examples

The following examples all return 15:

parseInt("F", 16)
parseInt("17", 8)
parseInt("15", 10)
parseInt(15.99, 10)
parseInt("FXX123", 16)
parseInt("1111", 2)
parseInt("15*3", 10)
The following examples all return "NaN":

parseInt("Hello", 8)
parseInt("0x7", 10)
parseInt("FFF", 10)
Even though the radix is specified differently, the following examples all return 17 because the input string begins with "0x".

parseInt("0x11", 16)
parseInt("0x11", 0)
parseInt("0x11")

See also

isNaN, parseFloat, Object.valueOf


redirect

Redirects the client to the specified URL.

Server-side function

Implemented in

LiveWire 1.0

Syntax

redirect(location)

Parameters

location
The URL to which you want to redirect the client.

Description

The redirect function is a top-level server-side JavaScript function that is not associated with any object.

The redirect function redirects the client browser to the URL specified by the location parameter. The value of location can be relative or absolute.

When the client encounters a redirect function, it loads the specified page immediately and discards the current page. The client does not execute or load any HTML or script statements in the page following the redirect function.

You can use the addClient function to preserve client object property values. See addClient for more information.

Examples

The following example uses the redirect function to redirect a client browser:

redirect("http://www.royalairways.com/lw/apps/newhome.html")
The page displayed by the newhome.html link could contain content such as the following:

<H1>New location</H1>
The URL you tried to access has been moved to:<BR>
<LI><A HREF=http://www.royalairways.com/lw/apps/index.html>
   http://www.royalairways.com/lw/apps/index.html</A>
<P>This notice will remain until 12/31/97.

See also

addClient

(Sebelumnya) Debug, deleteResponseHeader, e ...registerCFunction, ssjs_genera ... (Berikutnya)