The Request.QueryString command is used to collect values in a form with method="get".
Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.
If a user typed "Bill" and "Gates" in the HTML form above, the URL sent to the server would look like this:
http://www.w3schools.com/simpleform.asp?fname=Bill&lname=Gates
Assume that "simpleform.asp" contains the following ASP script:
Welcome
<% response.write(request.querystring("fname")) response.write(" " & request.querystring("lname")) %>
The browser will display the following in the body of the document:
Welcome Bill Gates
Examples
A form with method="get"
How to interact with the user, with the Request.QueryString command.
Your name:
<% dim fname fname=Request.QueryString("fname") If fname<>"" Then
Response.Write("Hello " & fname & "!
")
Response.Write("How are you today?")
End If
%>
Monday, March 22, 2010
ASP Forms and User Input
The Request.QueryString and Request.Form commands are used to retrieve user input from forms.
User Input
The Request object can be used to retrieve user information from forms.
Example HTML form
First Name:
Last Name:
User input can be retrieved with the Request.QueryString or Request.Form command.
User Input
The Request object can be used to retrieve user information from forms.
Example HTML form
First Name:
Last Name:
User input can be retrieved with the Request.QueryString or Request.Form command.
Differences between VBScript and JavaScript
When calling a VBScript or a JavaScript procedure from an ASP file written in VBScript, you can use the "call" keyword followed by the procedure name. If a procedure requires parameters, the parameter list must be enclosed in parentheses when using the "call" keyword. If you omit the "call" keyword, the parameter list must not be enclosed in parentheses. If the procedure has no parameters, the parentheses are optional.
When calling a JavaScript or a VBScript procedure from an ASP file written in JavaScript, always use parentheses after the procedure name.
When calling a JavaScript or a VBScript procedure from an ASP file written in JavaScript, always use parentheses after the procedure name.
ASP Procedures
In ASP you can call a JavaScript procedure from a VBScript and vice versa.
________________________________________
Procedures
The ASP source code can contain procedures and functions:
Example
<% sub vbproc(num1,num2) response.write(num1*num2) end sub %>
You can call a procedure like this:
Result: <%call vbproc(3,4)%>
Or, like this:
Result: <%vbproc 3,4%>
Insert the <%@ language="language" %> line above the tag to write the procedure/function in another scripting language:
Example
<%@ language="javascript" %>
<% function jsproc(num1,num2) { Response.Write(num1*num2) } %>
Result: <%jsproc(3,4)%>
________________________________________
Procedures
The ASP source code can contain procedures and functions:
Example
<% sub vbproc(num1,num2) response.write(num1*num2) end sub %>
You can call a procedure like this:
Result: <%call vbproc(3,4)%>
Or, like this:
Result: <%vbproc 3,4%>
Insert the <%@ language="language" %> line above the tag to write the procedure/function in another scripting language:
Example
<%@ language="javascript" %>
<% function jsproc(num1,num2) { Response.Write(num1*num2) } %>
Result: <%jsproc(3,4)%>
Session Variables in asp
Session variables are used to store information about ONE single user, and are available to all pages in one application. Typically information stored in session variables are name, id, and preferences.
Application Variables
Application variables are also available to all pages in one application. Application variables are used to store information about ALL users in one specific application.
Application Variables
Application variables are also available to all pages in one application. Application variables are used to store information about ALL users in one specific application.
Lifetime of Variables in active server pages
A variable declared outside a procedure can be accessed and changed by any script in the ASP file.
A variable declared inside a procedure is created and destroyed every time the procedure is executed. No scripts outside the procedure can access or change the variable.
To declare variables accessible to more than one ASP file, declare them as session variables or application variables.
A variable declared inside a procedure is created and destroyed every time the procedure is executed. No scripts outside the procedure can access or change the variable.
To declare variables accessible to more than one ASP file, declare them as session variables or application variables.
Declare an array in active server pages
Arrays are used to store a series of related data items. The following example demonstrates how to declare an array that stores names.
Loop through the HTML headings
How to loop through the six headings in HTML.
Time-based greeting using VBScript
This example will display a different message to the user depending on the time on the server.
Time-based greeting using JavaScript
This example is the same as the one above, but the syntax is different.
Loop through the HTML headings
How to loop through the six headings in HTML.
Time-based greeting using VBScript
This example will display a different message to the user depending on the time on the server.
Time-based greeting using JavaScript
This example is the same as the one above, but the syntax is different.
ASP Variables
A variable is used to store information.
Declaring a variable:
Variables are used to store information. The following example demonstrates how to declare a variable, assign a value to it, and use the value in a text.
Declaring a variable:
Variables are used to store information. The following example demonstrates how to declare a variable, assign a value to it, and use the value in a text.
Other Scripting Languages
Other Scripting Languages
ASP is shipped with VBScript and JScript (Microsoft's implementation of JavaScript). If you want to script in another language, like PERL, REXX, or Python, you will have to install script engines for them.
ASP is shipped with VBScript and JScript (Microsoft's implementation of JavaScript). If you want to script in another language, like PERL, REXX, or Python, you will have to install script engines for them.
ASP Basic Syntax Rules
Write Output to a Browser
An ASP file normally contains HTML tags, just like an HTML file. However, an ASP file can also contain server scripts, surrounded by the delimiters <% and %>.
Server scripts are executed on the server, and can contain any expressions, statements, procedures, or operators valid for the scripting language you prefer to use.
The response.write Command
The response.write command is used to write output to a browser. The following example sends the text "Hello World" to the browser:
Example
<% response.write("Hello World!") %>
There is also a shorthand method for the response.write command. The following example also sends the text "Hello World" to the browser:
Example
<% ="Hello World!" %>
The example above writes "Hello World!" into the body of the document.
________________________________________
Using JavaScript in ASP
To set JavaScript as the default scripting language for a particular page you must insert a language specification at the top of the page:
<%@ language="javascript"%>
<% Response.Write("Hello World!") %>
Note: JavaScript is case sensitive! You will have to write your ASP code with uppercase letters and lowercase letters when the language requires it.
An ASP file normally contains HTML tags, just like an HTML file. However, an ASP file can also contain server scripts, surrounded by the delimiters <% and %>.
Server scripts are executed on the server, and can contain any expressions, statements, procedures, or operators valid for the scripting language you prefer to use.
The response.write Command
The response.write command is used to write output to a browser. The following example sends the text "Hello World" to the browser:
Example
<% response.write("Hello World!") %>
There is also a shorthand method for the response.write command. The following example also sends the text "Hello World" to the browser:
Example
<% ="Hello World!" %>
The example above writes "Hello World!" into the body of the document.
________________________________________
Using JavaScript in ASP
To set JavaScript as the default scripting language for a particular page you must insert a language specification at the top of the page:
<%@ language="javascript"%>
<% Response.Write("Hello World!") %>
Note: JavaScript is case sensitive! You will have to write your ASP code with uppercase letters and lowercase letters when the language requires it.
Subscribe to:
Posts (Atom)