VBScript InputBoxFunction
Complete VBScript Reference Manual
The InputBox function displays a dialog box in which the user can enter text and/or click a button. If the user clicks the OK button or presses the ENTER key on the keyboard, the InputBox function returns the text in the text box. If the user clicks the Cancel button, the function returns an empty string ("").
Note:If both the helpfile and context parameters are specified, a Help button is added to the dialog box.
Tip:See the MsgBox function.
Syntax
InputBox(prompt[,title][,default][,xpos][,ypos][,helpfile,context])
| Parameters | Description |
|---|---|
| prompt | Required. The message displayed in the dialog box. The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used. If prompt contains multiple lines, you can separate the lines using carriage return characters (Chr(13)), linefeed characters (Chr(10)), or a combination of carriage return and linefeed characters (Chr(13) & Chr(10)). |
| title | Optional. The title of the dialog box. The default is the name of the application. |
| default | Optional. A default text string displayed in the text box. |
| xpos | Optional. A numeric expression that specifies the horizontal distance (in twips*) between the left edge of the dialog box and the left edge of the screen. If xpos is omitted, the dialog box is horizontally centered. |
| ypos | Optional. A numeric expression that specifies the vertical distance (in twips*) between the top edge of the dialog box and the top edge of the screen. If ypos is omitted, the dialog box is displayed at approximately one-third of the vertical distance from the bottom edge of the screen. |
| helpfile | Optional. A string expression that identifies the help file that provides context-sensitive help for the dialog box. It must be used together with the context parameter. |
| context | Optional. A numeric expression that identifies the context number assigned to a help topic by the help file author. It must be used together with the helpfile parameter. |
* A twip is a unit of measurement, which is visually the same as the system display.
1 twip is 1/1440 of an inch.
Examples
Example 1
<script type="text/vbscript">
Function myFunction()
fname=InputBox("Enter your name")
End Function
</script>
Function myFunction()
fname=InputBox("Enter your name")
End Function
</script>
Try it Yourself »
Example 2
Prompt box with a title:
<script type="text/vbscript">
Function myFunction()
fname=InputBox("Enter your name","Userinput")
End Function
</script>
Function myFunction()
fname=InputBox("Enter your name","Userinput")
End Function
</script>
Try it Yourself »
Example 3
Prompt box with default text in the input box:
<script type="text/vbscript">
Function myFunction()
fname=InputBox("Enter your name",,"Donald Duck")
End Function
</script>
Function myFunction()
fname=InputBox("Enter your name",,"Donald Duck")
End Function
</script>
Try it Yourself »
Example 4
A prompt box displayed at a position 700 twips* from the left edge of the screen.
<script type="text/vbscript">
Function myFunction()
fname=InputBox("Enter your name",,,700)
End Function
</script>
Function myFunction()
fname=InputBox("Enter your name",,,700)
End Function
</script>
Try it Yourself »
Example 5
A prompt box displayed at a position 500 twips* from the top edge of the screen.
<script type="text/vbscript">
Function myFunction()
fname=InputBox("Enter your name",,,,500)
End Function
</script>
Function myFunction()
fname=InputBox("Enter your name",,,,500)
End Function
</script>
Try it Yourself »
Complete VBScript Reference Manual Other Extensions