search property

A string beginning with a question mark that specifies any query information in the URL.

Syntax

1. links[index].search
2. location.search

index is an integer representing a link object.

Property of

link, location

Description

The search property specifies a portion of the URL.

You can set the search property at any time, although it is safer to set the href property to change a location. If the search that you specify cannot be found in the current location, you will get an error.

See Section 3.3 of RFC 1738 for complete information about the search.

Examples

In the following example, the window.open statement creates a window called newWindow and loads the specified URL into it. The document.write statements display all the properties of newWindow.location in a window called msgWindow.

newWindow=window.open
   ("http://guide-p.infoseek.com/WW/NS/Titles?qt=RFC+1738+&col=WW")

msgWindow.document.write("newWindow.location.href = " +
   newWindow.location.href + "<P>")
msgWindow.document.write("newWindow.location.protocol = " +
   newWindow.location.protocol + "<P>")
msgWindow.document.write("newWindow.location.host = " +
   newWindow.location.host + "<P>")
msgWindow.document.write("newWindow.location.hostName = " +
   newWindow.location.hostName + "<P>")
msgWindow.document.write("newWindow.location.port = " +
   newWindow.location.port + "<P>")
msgWindow.document.write("newWindow.location.pathname = " +
   newWindow.location.pathname + "<P>")
msgWindow.document.write("newWindow.location.search = " +
   newWindow.location.search + "<P>")
msgWindow.document.write("newWindow.location.hash = " +
   newWindow.location.hash + "<P>")
msgWindow.document.close()

The previous example displays the following output:

newWindow.location.href =
   http://guide-p.infoseek.com/WW/NS/Titles?qt=RFC+1738+&col=WW
newWindow.location.protocol = http:
newWindow.location.host = guide-p.infoseek.com
newWindow.location.hostName = guide-p.infoseek.com
newWindow.location.port = 
newWindow.location.pathname = /WW/NS/Titles
newWindow.location.search = ?qt=RFC+1738+&col=WW
newWindow.location.hash = 

See also

  • hash, host, hostname, href, pathname, port, protocol properties

    select method

    Selects the input area of the specified password, text, or textarea object.

    Syntax

    1. passwordName.select()
    2. textName.select()
    3. textareaName.select()
    

    passwordName is either the value of the NAME attribute of a password object or an element in the elements array.
    textName is either the value of the NAME attribute of a text object or an element in the elements array.
    textareaName is either the value of the NAME attribute of a textarea object or an element in the elements array.

    Method of

    password, text, textarea

    Description

    Use the select method to highlight the input area of a form element. You can use the select method with the focus method to highlight a field and position the cursor for a user response.

    Examples

    In the following example, the checkPassword function confirms that a user has entered a valid password. If the password is not valid, the select method highlights the password field and the focus method returns focus to it so the user can re-enter the password.

    function checkPassword(userPass) {
       if (badPassword) {
          alert("Please enter your password again.")
          userPass.focus()
          userPass.select()
       }
    }
    This example assumes that the password is defined as:
    <INPUT TYPE="password" NAME="userPass">

    See also

  • blur, focus methods

    select object (options array)

    A selection list or scrolling list on an HTML form. A selection list lets the user choose one item from a list. A scrolling list lets the user choose one or more items from a list.

    Syntax

    To define a select object, use standard HTML syntax with the addition of the onBlur, onChange, and onFocus event handlers:

    <SELECT
       NAME="selectName"
       [SIZE="integer"]
       [MULTIPLE]
       [onBlur="handlerText"]
       [onChange="handlerText"]
       [onFocus="handlerText"]>
       <OPTION VALUE="optionValue" [SELECTED]> textToDisplay [ ... <OPTION> textToDisplay]
    </SELECT>
    
    NAME="selectName" specifies the name of the select object. You can access this value using the name property.
    SIZE="integer" specifies the number of options visible when the form is displayed.
    MULTIPLE specifies that the select object is a scrolling list (not a selection list).
    OPTION specifies a selection element in the list. You can access the options using the options array.
    VALUE="optionValue" specifies a value that is returned to the server when the option is selected and the form is submitted. You can access this value using the value property.
    SELECTED specifies that the option is selected by default. You can access this value using the defaultSelected property.
    textToDisplay specifies the text to display in the list. You can access this value using the text property.

    To use a select object's properties and methods:

    1. selectName.propertyName
    2. selectName.methodName(parameters)
    3. formName.elements[index].propertyName
    4. formName.elements[index].methodName(parameters)
    
    selectName is the value of the NAME attribute of a select object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a select object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    To use an option's properties:

    1. selectName.options[index1].propertyName
    2. formName.elements[index2].options[index1].propertyName
    
    selectName is the value of the NAME attribute of a select object.
    index1 is an integer representing an option in a select object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index2 is an integer representing a select object on a form.
    propertyName is one of the properties listed below.

    Property of

  • The select object is a property of form
  • The options array is a property of select

    Description

    A select object on a form looks as follows. The object on the left is a selection list that lets the user choose one item; the object on the right is a scrolling list that lets the user choose one or more items:

    A select object is a form element and must be defined within a <FORM> tag.

    The options array

    You can reference the options of a select object in your code by using the options array. This array contains an entry for each option in a select object (<OPTION> tag) in source order. For example, if a select object named musicStyle contains three options, these options are reflected as musicStyle.options[0], musicStyle.options[1], and musicStyle.options[2].

    To use the options array:

    1. selectName.options
    2. selectName.options[index]
    3. selectName.options.length
    

    selectName is either the value of the NAME attribute of a select object or an element in the elements array.
    index is an integer representing an option in a select object.

    To obtain the number of options in a select object, use the length property of either the options array or the select object:

    1. selectName.length
    2. selectName.options.length
    

    The select object has properties that you can access only through the options array. These properties are listed below.

    Even though each element in the options array represents a select option, the value of options[index] is always null. The value returned by selectName.options represents the full HTML statement for the selectName object.

    Elements in the options array are read-only. For example, the statement selectName.options[0]="guitar" has no effect.

    Properties

    The select object has the following properties:

  • length reflects the number of options in a select object
  • name reflects the NAME attribute
  • options reflects the <OPTION> tags
  • selectedIndex reflects the index of the selected option (or the first selected option, if multiple options are selected)

    The options array has the following properties:

  • defaultSelected reflects the SELECTED attribute
  • index reflects the index of an option
  • length reflects the number of options in a select object
  • name reflects the NAME attribute
  • selected lets you programatically select an option
  • selectedIndex reflects the index of the selected option
  • text reflects the textToDisplay that follows an <OPTION> tag
  • value reflects the VALUE attribute

    Methods

  • blur
  • focus

    Event handlers

  • onBlur
  • onChange
  • onFocus

    Examples

    Example 1. The following example displays a selection list and a scrolling list.

    Choose the music type for your free CD: <SELECT NAME="music_type_single"> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT> <P>Choose the music types for your free CDs: <BR><SELECT NAME="music_type_multi" MULTIPLE> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT>

    Example 2. The following example displays two selection lists that let the user choose a month and day. These selection lists are initialized to the current date. The user can change the month and day by using the selection lists or by choosing preset dates from radio buttons. Text fields on the form display the values of the select object's properties and indicate the date chosen and whether it is Cinco de Mayo.

    <HTML> <HEAD> <TITLE>Select object example</TITLE> </HEAD> <BODY> <SCRIPT> var today = new Date() //--------------- function updatePropertyDisplay(monthObj,dayObj) { // Get date strings var monthInteger, dayInteger, monthString, dayString monthInteger=monthObj.selectedIndex dayInteger=dayObj.selectedIndex monthString=monthObj.options[monthInteger].text dayString=dayObj.options[dayInteger].text // Display property values document.selectForm.textFullDate.value=monthString + " " + dayString document.selectForm.textMonthLength.value=monthObj.length document.selectForm.textDayLength.value=dayObj.length document.selectForm.textMonthName.value=monthObj.name document.selectForm.textDayName.value=dayObj.name document.selectForm.textMonthIndex.value=monthObj.selectedIndex document.selectForm.textDayIndex.value=dayObj.selectedIndex // Is it Cinco de Mayo? if (monthObj.options[4].selected && dayObj.options[4].selected) document.selectForm.textCinco.value="Yes!" else document.selectForm.textCinco.value="No" } </SCRIPT> <!---------------> <FORM NAME="selectForm"> <P><B>Choose a month and day:</B> Month: <SELECT NAME="monthSelection" onChange="updatePropertyDisplay(this,document.selectForm.daySelection)"> <OPTION> January <OPTION> February <OPTION> March <OPTION> April <OPTION> May <OPTION> June <OPTION> July <OPTION> August <OPTION> September <OPTION> October <OPTION> November <OPTION> December </SELECT> Day: <SELECT NAME="daySelection" onChange="updatePropertyDisplay(document.selectForm.monthSelection,this)"> <OPTION> 1 <OPTION> 2 <OPTION> 3 <OPTION> 4 <OPTION> 5 <OPTION> 6 <OPTION> 7 <OPTION> 8 <OPTION> 9 <OPTION> 10 <OPTION> 11 <OPTION> 12 <OPTION> 13 <OPTION> 14 <OPTION> 15 <OPTION> 16 <OPTION> 17 <OPTION> 18 <OPTION> 19 <OPTION> 20 <OPTION> 21 <OPTION> 22 <OPTION> 23 <OPTION> 24 <OPTION> 25 <OPTION> 26 <OPTION> 27 <OPTION> 28 <OPTION> 29 <OPTION> 30 <OPTION> 31 </SELECT> <P><B>Set the date to: </B> <INPUT TYPE="radio" NAME="dateChoice" onClick=" monthSelection.selectedIndex=0; daySelection.selectedIndex=0; updatePropertyDisplay(document.selectForm.monthSelection,document.selectForm.daySelection)"> New Year's Day <INPUT TYPE="radio" NAME="dateChoice" onClick=" monthSelection.selectedIndex=4; daySelection.selectedIndex=4; updatePropertyDisplay(document.selectForm.monthSelection,document.selectForm.daySelection)"> Cinco de Mayo <INPUT TYPE="radio" NAME="dateChoice" onClick=" monthSelection.selectedIndex=5; daySelection.selectedIndex=20; updatePropertyDisplay(document.selectForm.monthSelection,document.selectForm.daySelection)"> Summer Solstice <P><B>Property values:</B> <BR>Date chosen: <INPUT TYPE="text" NAME="textFullDate" VALUE="" SIZE=20"> <BR>monthSelection.length<INPUT TYPE="text" NAME="textMonthLength" VALUE="" SIZE=20"> <BR>daySelection.length<INPUT TYPE="text" NAME="textDayLength" VALUE="" SIZE=20"> <BR>monthSelection.name<INPUT TYPE="text" NAME="textMonthName" VALUE="" SIZE=20"> <BR>daySelection.name<INPUT TYPE="text" NAME="textDayName" VALUE="" SIZE=20"> <BR>monthSelection.selectedIndex<INPUT TYPE="text" NAME="textMonthIndex" VALUE="" SIZE=20"> <BR>daySelection.selectedIndex<INPUT TYPE="text" NAME="textDayIndex" VALUE="" SIZE=20"> <BR>Is it Cinco de Mayo? <INPUT TYPE="text" NAME="textCinco" VALUE="" SIZE=20"> <SCRIPT> document.selectForm.monthSelection.selectedIndex=today.getMonth() document.selectForm.daySelection.selectedIndex=today.getDate()-1 updatePropertyDisplay(document.selectForm.monthSelection,document.selectForm.daySelection) </SCRIPT> </FORM> </BODY> </HTML>

    See also the examples for the defaultSelected property.

    See also

  • form and radio objects

    selected property

    A Boolean value specifying the current selection state of an option in a select object.

    Syntax

    selectName.options[index].selected

    selectName is either the value of the NAME attribute of a select object or an element in the elements array.
    index is an integer representing an option in a select object.

    Property of

    options array

    Description

    If an option in a select object is selected, the value of its selected property is true; otherwise, it is false.

    You can set the selected property at any time. The display of the select object updates immediately when you set the selected property.

    In general, the selected property is more useful than the selectedIndex property for select objects that are created with the MULTIPLE attribute. With the selected property, you can evaluate every option in the options array to determine multiple selections, and you can select individual options without clearing the selection of other options.

    Examples

    See the examples for the defaultSelected property.

    See also

  • defaultSelected, index, selectedIndex properties

    selectedIndex property

    An integer specifying the index of the selected option in a select object.

    Syntax

    1. selectName.selectedIndex
    2. selectName.options.selectedIndex
    

    selectName is either the value of the NAME attribute of a select object or an element in the elements array.

    Property of

  • select
  • options array

    Description

    Options in a select object are indexed in the order in which they are defined, starting with an index of 0. You can set the selectedIndex property at any time. The display of the select object updates immediately when you set the selectedIndex property. Both forms of the syntax specify the same value.

    In general, the selectedIndex property is more useful for select objects that are created without the MULTIPLE attribute. If you evaluate selectedIndex when multiple options are selected, the selectedIndex property specifies the index of the first option only. Setting selectedIndex clears any other options that are selected in the select object.

    The selected property of the select object's options array is more useful for select objects that are created with the MULTIPLE attribute. With the selected property, you can evaluate every option in the options array to determine multiple selections, and you can select individual options without clearing the selection of other options.

    Examples

    In the following example, the getSelectedIndex() function returns the selected index in the musicType select object:

    function getSelectedIndex() {
       return document.musicForm.musicType.selectedIndex
    }
    
    The previous example assumes that the select object is similar to the following:
    <SELECT NAME="musicType"> 
       <OPTION SELECTED> R&B
       <OPTION> Jazz
       <OPTION> Blues
       <OPTION> New Age
    </SELECT>
    

    See also

  • defaultSelected, index, selected properties

    self property

    The self property is a synonym for the current window or frame.

    Syntax

    1. self.propertyName
    2. self.methodName
    

    propertyName is the defaultStatus, status, length, or name property when self refers to a window object.
    propertyName is the length or name property when self refers to a frame object.
    methodName is any method associated with the window object.

    Property of

    frame, window

    Description

    The self property refers to the current window or frame.

    Use the self property to disambiguate a window property from a form or form element of the same name. You can also use the self property to make your code more readable.

    The self property is read-only. The value of the self property is

         <object nameAttribute>
    where nameAttribute is the NAME attribute if self refers to a frame, or an internal reference if self refers to a window.

    Examples

    In the following example, self.status is used to set the status property of the current window. This usage disambiguates the status property of the current window from a form or form element called "status" within the current window.

    <A HREF="" onClick="this.href=pickRandomURL()" onMouseOver="self.status='Pick a random URL' ; return true"> Go!</A>

    See also

  • window property

    setDate method

    Sets the day of the month for a specified date.

    Syntax

    dateObjectName.setDate(dayValue)

    dateObjectName is either the name of a date object or a property of an existing object.
    dayValue is an integer from 1 to 31 or a property of an existing object, representing the day of the month.

    Method of

    Date

    Examples

    The second statement below changes the day for theBigDay to the 24th of July from its original value.

    theBigDay = new Date("July 27, 1962 23:30:00")
    theBigDay.setDate(24)
    

    See also

  • getDate method

    setHours method

    Sets the hours for a specified date.

    Syntax

    dateObjectName.setHours(hoursValue)

    dateObjectName is either the name of a date object or a property of an existing object.
    hoursValue is an integer between 0 and 23 or a property of an existing object, representing the hour.

    Method of

    Date

    Examples

    theBigDay.setHours(7)
    

    See also

  • getHours method

    setMinutes method

    Sets the minutes for a specified date.

    Syntax

    dateObjectName.setMinutes(minutesValue)

    dateObjectName is either the name of a date object or a property of an existing object.
    minutesValue is an integer between 0 and 59 or a property of an existing object, representing the minutes.

    Method of

    Date

    Examples

    theBigDay.setMinutes(45)
    

    See also

  • getMinutes method

    setMonth method

    Sets the month for a specified date.

    Syntax

    dateObjectName.setMonth(monthValue)

    dateObjectName is either the name of a date object or a property of an existing object.
    monthValue is an integer between 0 and 11 (representing the months January through December), or a property of an existing object.

    Method of

    Date

    Examples

    theBigDay.setMonth(6)
    

    See also

  • getMonth method

    setSeconds method

    Sets the seconds for a specified date.

    Syntax

    dateObjectName.setSeconds(secondsValue)

    dateObjectName is either the name of a date object or a property of an existing object.
    secondsValue is an integer between 0 and 59 or a property of an existing object.

    Method of

    Date

    Examples

    theBigDay.setSeconds(30)
    

    See also

  • getSeconds method

    setTime method

    Sets the value of a date object.

    Syntax

    dateObjectName.setTime(timevalue) 

    dateObjectName is either the name of a date object or a property of an existing object.
    timevalue is an integer or a property of an existing object, representing the number of milliseconds since the epoch (1 January 1970 00:00:00).

    Method of

    Date

    Description

    Use the setTime method to help assign a date and time to another date object.

    Examples

    theBigDay = new Date("July 1, 1999")
    sameAsBigDay = new Date()
    sameAsBigDay.setTime(theBigDay.getTime())
    

    See also

  • getTime method

    setTimeout method

    Evaluates an expression after a specified number of milliseconds have elapsed.

    Syntax

    timeoutID=setTimeout(expression, msec)

    timeoutID is an identifier that is used only to cancel the evaluation with the clearTimeout method.
    expression is a string expression or a property of an existing object.
    msec is a numeric value, numeric string, or a property of an existing object in millisecond units.

    Method of

    frame, window

    Description

    The setTimeout method evaluates an expression after a specified amount of time. It does not evaluate the expression repeatedly. For example, if a setTimeout method specifies 5 seconds, the expression is evaluated after 5 seconds, not every 5 seconds.

    Examples

    Example 1. The following example displays an alert message 5 seconds (5,000 milliseconds) after the user clicks a button. If the user clicks the second button before the alert message is displayed, the timeout is canceled and the alert does not display.

    <SCRIPT LANGUAGE="JavaScript"> function displayAlert() { alert("5 seconds have elapsed since the button was clicked.") } </SCRIPT> <BODY> <FORM> Click the button on the left for a reminder in 5 seconds; click the button on the right to cancel the reminder before it is displayed. <P> <INPUT TYPE="button" VALUE="5-second reminder" NAME="remind_button" onClick="timerID=setTimeout('displayAlert()',5000)"> <INPUT TYPE="button" VALUE="Clear the 5-second reminder" NAME="remind_disable_button" onClick="clearTimeout(timerID)"> </FORM> </BODY>

    Example 2. The following example displays the current time in a text object. The showtime() function, which is called recursively, uses the setTimeout method update the time every second.

    <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- var timerID = null var timerRunning = false function stopclock(){ if(timerRunning) clearTimeout(timerID) timerRunning = false } function startclock(){ // Make sure the clock is stopped stopclock() showtime() } function showtime(){ var now = new Date() var hours = now.getHours() var minutes = now.getMinutes() var seconds = now.getSeconds() var timeValue = "" + ((hours > 12) ? hours - 12 : hours) timeValue += ((minutes < 10) ? ":0" : ":") + minutes timeValue += ((seconds < 10) ? ":0" : ":") + seconds timeValue += (hours >= 12) ? " P.M." : " A.M." document.clock.face.value = timeValue timerID = setTimeout("showtime()",1000) timerRunning = true } //--> </SCRIPT> </HEAD> <BODY onLoad="startclock()"> <FORM NAME="clock" onSubmit="0"> <INPUT TYPE="text" NAME="face" SIZE=12 VALUE =""> </FORM> </BODY>

    See also

  • clearTimeout method

    setYear method

    Sets the year for a specified date.

    Syntax

    dateObjectName.setYear(yearValue)

    dateObjectName is either the name of a date object or a property of an existing object.
    yearValue is an integer greater than 1900 or a property of an existing object.

    Method of

    Date

    Examples

    theBigDay.setYear(96)
    

    See also

  • getYear method

    sin method

    Returns the sine of a number.

    Syntax

    Math.sin(number)

    number is a numeric expression or a property of an existing object, representing the size of an angle in radians.

    Method of

    Math

    Description

    The sin method returns a numeric value between -1 and 1, which represents the sine of the angle.

    Examples

    //Displays the value 1
    document.write("The sine of pi/2 radians is " +
       Math.sin(Math.PI/2))
    
    //Displays the value 1.224606353822377e-016
    document.write("<P>The sine of pi radians is " +
       Math.sin(Math.PI))
    
    //Displays the value 0
    document.write("<P>The sine of 0 radians is " +
       Math.sin(0))
    

    See also

  • acos, asin, atan, cos, tan methods

    small method

    Causes a string to be displayed in a small font as if it were in a <SMALL> tag.

    Syntax

    stringName.small()

    stringName is any string or a property of an existing object.

    Method of

    string

    Description

    Use the small method with the write or writeln methods to format and display a string in a document.

    Examples

    The following example uses string methods to change the size of a string:
    var worldString="Hello, world"
    
    document.write(worldString.small())
    document.write("<P>" + worldString.big())
    document.write("<P>" + worldString.fontsize(7))
    

    The previous example produces the same output as the following HTML:

    <SMALL>Hello, world</SMALL>
    <P><BIG>Hello, world</BIG>
    <P><FONTSIZE=7>Hello, world</FONTSIZE>
    

    See also

  • big, fontsize methods

    sqrt method

    Returns the square root of a number.

    Syntax

    Math.sqrt(number)
    number is any non-negative numeric expression or a property of an existing object.

    Method of

    Math

    Description

    If the value of number is outside the suggested range, the return value is always 0.

    Examples

    //Displays the value 3
    document.write("The square root of 9 is " + Math.sqrt(9))
    
    //Displays the value 1.414213562373095
    document.write("<P>The square root of 2 is " + Math.sqrt(2))
    
    //Displays the value 0 because the argument is out of range
    document.write("<P>The square root of -1 is " + Math.sqrt(-1))
    

    SQRT1_2 property

    The square root of one-half; equivalently, one over the square root of two, approximately 0.707.

    Syntax

    Math.SQRT1_2

    Property of

    Math

    Description

    Because SQRT1_2 is a constant, it is a read-only property of Math.

    Examples

    The following example displays 1 over the square root of 2:

    document.write("1 over the square root of 2 is " + Math.SQRT1_2)

    See also

  • E, LN2, LN10, LOG2E, LOG10E, PI, SQRT2 properties

    SQRT2 property

    The square root of two, approximately 1.414.

    Syntax

    Math.SQRT2

    Property of

    Math

    Description

    Because SQRT2 is a constant, it is a read-only property of Math.

    Examples

    The following example displays the square root of 2:

    document.write("The square root of 2 is " + Math.SQRT2)

    See also

  • E, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2 properties

    status property

    Specifies a priority or transient message in the status bar at the bottom of the window, such as the message that appears when a mouseOver event occurs over an anchor.

    Syntax

    windowReference.status

    windowReference is a valid way of referring to a window, as described in the window object.

    Property of

    window

    Description

    Do not confuse the status property with the defaultStatus property. The defaultStatus property reflects the default message displayed in the status bar.

    You can set the status property at any time. You must return true if you want to set the status property in the onMouseOver event handler.

    Examples

    Suppose you have created a JavaScript function called pickRandomURL() that lets you select a URL at random. You can use the onClick event handler of an anchor to specify a value for the HREF attribute of the anchor dynamically, and the onMouseOver event handler to specify a custom message for the window in the status property:

    <A HREF="" onClick="this.href=pickRandomURL()" onMouseOver="self.status='Pick a random URL'; return true"> Go!</A>

    In the above example, the status property of the window is assigned to the window's self property, as self.status. As this example shows, you must return true to set the status property in the onMouseOver event handler.

    See also

  • defaultStatus property

    strike method

    Causes a string to be displayed as struck out text as if it were in a <STRIKE> tag.

    Syntax

    stringName.strike()

    stringName is any string or a property of an existing object.

    Method of

    string

    Description

    Use the strike method with the write or writeln methods to format and display a string in a document.

    Examples

    The following example uses string methods to change the formatting of a string:
    var worldString="Hello, world"
    
    document.write(worldString.blink())
    document.write("<P>" + worldString.bold())
    document.write("<P>" + worldString.italics())
    document.write("<P>" + worldString.strike())
    

    The previous example produces the same output as the following HTML:

    <BLINK>Hello, world</BLINK>
    <P><B>Hello, world</B>
    <P><I>Hello, world</I>
    <P><STRIKE>Hello, world</STRIKE>
    

    See also

  • blink, bold, italics methods

    string object

    A series of characters.

    Syntax

    To use a string object:

    1. stringName.propertyName
    2. stringName.methodName(parameters)
    
    stringName is the name of a string variable.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Property of

  • None.

    Description

    The string object is a built-in JavaScript object.

    A string can be represented as a literal enclosed by single or double quotes; for example, "Netscape" or 'Netscape'.

    Properties

  • length reflects the length of the string

    Methods

  • anchor
  • big
  • blink
  • bold
  • charAt
  • fixed
  • fontcolor
  • fontsize
  • indexOf
  • italics
  • lastIndexOf
  • link
  • small
  • strike
  • sub
  • substring
  • sup
  • toLowerCase
  • toUpperCase

    Event handlers

  • None. Built-in objects do not have event handlers.

    Examples

    The following statement creates a string variable.

    var last_name = "Schaefer" The following statements evaluate to 8, "SCHAEFER", and "schaefer": last_name.length last_name.toUpperCase() last_name.toLowerCase()

    See also

  • text and textarea objects

    sub method

    Causes a string to be displayed as a subscript as if it were in a <SUB> tag.

    Syntax

    stringName.sub()

    stringName is any string or a property of an existing object.

    Method of

    string

    Description

    Use the sub method with the write or writeln methods to format and display a string in a document.

    Examples

    The following example uses the sub and sup methods to format a string:
    var superText="superscript"
    var subText="subscript"
    
    document.write("This is what a " + superText.sup() + " looks like.")
    document.write("<P>This is what a " + subText.sub() + " looks like.")
    

    The previous example produces the same output as the following HTML:

    This is what a <SUP>superscript</SUP> looks like.
    <P>This is what a <SUB>subscript</SUB> looks like.
    

    See also

    sup method


    submit method

    Submits a form.

    Syntax

    formName.submit()

    formName is the name of any form or an element in the forms array.

    Method of

    form

    Description

    The submit method submits the specified form. It performs the same action as a submit button.

    Use the submit method to send data back to an http server. The submit method returns the data using either "get" or "post", as specified in the method property.

    Examples

    The following example submits a form called musicChoice:

    document.musicChoice.submit()
    

    If musicChoice is the first form created, you also can submit it as follows:

    document.forms[0].submit()
    

    See also the example for the form object.

    See also

  • submit object
  • onSubmit event handler

    submit object

    A submit button on an HTML form. A submit button causes a form to be submitted.

    Syntax

    To define a submit button, use standard HTML syntax with the addition of the onClick event handler:

    <INPUT
       TYPE="submit"
       NAME="submitName"
       VALUE="buttonText"
       [onClick="handlerText"]>
    
    NAME="submitName" specifies the name of the submit object. You can access this value using the name property.
    VALUE="buttonText" specifies the label to display on the button face. You can access this value using the value property.

    To use a submit object's properties and methods:

    1. submitName.propertyName
    2. submitName.methodName(parameters)
    3. formName.elements[index].propertyName
    4. formName.elements[index].methodName(parameters)
    
    submitName is the value of the NAME attribute of a submit object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a submit object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Property of

  • form

    Description

    A submit object on a form looks as follows:

    A submit object is a form element and must be defined within a <FORM> tag.

    Clicking a submit button submits a form to the URL specified by the form's action property. This action always loads a new page into the client; it may be the same as the current page, if the action so specifies or is not specified.

    The submit button's onClick event handler cannot prevent a form from being submitted; instead, use the form's onSubmit event handler or use the submit method instead of a submit object. See the examples for the form object.

    Properties

  • name reflects the NAME attribute
  • value reflects the VALUE attribute

    Methods

  • click

    Event handlers

  • onClick

    Examples

    The following example creates a submit object called submit_button. The text "Done" is displayed on the face of the button.

    <INPUT TYPE="submit" NAME="submit_button" VALUE="Done">

    See also the examples for the form object.

    See also

  • button, form, and reset objects
  • submit method
  • onSubmit event handler

    substring method

    Returns a subset of a string object.

    Syntax

    stringName.substring(indexA, indexB)

    stringName is any string or a property of an existing object.
    indexA is any integer from 0 to stringName.length - 1, or a property of an existing object.
    indexB is any integer from 0 to stringName.length - 1, or a property of an existing object.

    Method of

    string

    Description

    Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character is stringName.length - 1.

    If indexA is less than indexB, the substring method returns the subset starting with the character at indexA and ending with the character before indexB. If indexA is greater than indexB, the substring method returns the subset starting with the character at indexB and ending with the character before indexA. If indexA is equal to indexB, the substring method returns the empty string.

    Examples

    The following example uses substring to display characters from the string "Netscape".
    var anyString="Netscape"
    
    //Displays "Net"
    document.write(anyString.substring(0,3))
    document.write(anyString.substring(3,0))
    //Displays "cap"
    document.write(anyString.substring(4,7))
    document.write(anyString.substring(7,4))
    

    sup method

    Causes a string to be displayed as a superscript as if it were in a <SUP> tag.

    Syntax

    stringName.sup()

    stringName is any string or a property of an existing object.

    Method of

    string

    Description

    Use the sup method with the write or writeln methods to format and display a string in a document.

    Examples

    The following example uses the sub and sup methods to format a string:
    var superText="superscript"
    var subText="subscript"
    
    document.write("This is what a " + superText.sup() + " looks like.")
    document.write("<P>This is what a " + subText.sub() + " looks like.")
    

    The previous example produces the same output as the following HTML:

    This is what a <SUP>superscript</SUP> looks like.
    <P>This is what a <SUB>subscript</SUB> looks like.
    

    See also

  • sub method