Best Industrial Training in C,C++,PHP,Dot Net,Java in Jalandhar

Tuesday 19 February 2013

Forms in ASP


Forms are the primary way that a user feeds information into ASP. A form is a web page that contains tags that cause the browser to show fields that the user can fill in.
Forms can be HTML files. They only need to be ASP if ASPy type capabilities are needed (session variables, includes).
The form must pass the variables onto a .asp file to process the form.

Form with GET

<form action="x.asp" name="whatever" method=get>
....
<input type=submit>
<input type=reset>
</form>
there is a limit on the number of characters (approximately 4,000 but varies depending on server and browsers involved.
The form will show it's parameter in the browser address window, for example:
testform.asp?state=md&city=Germantown
would be the URL in the browser, if the state and city field were populated.
An ASP script picks up a form field with:
<%whatever=request.querystring("whichfield")%>

Form with POST

<form action="x.asp" name="whatever" method="post">
....
<input type=submit>
<input type=reset>
</form>
It supports many more characters than get (megabytes of data in case of file uploads)
The form will not show it's parameter in the browser address window, for example:
http://whatever.com/testform.asp
would be the only URL in the browser, regardless of how many fields and how much data is passed.
An ASP script picks up the form field with:
<%whatever=request.form("whichfield")%>



Forms - TextBoxes

<Test Script Below>

<html><head>
<title>FormTextBox.asp</title>
</head><body bgcolor="#FFFFFF">
<Form action = "FormTextBoxRespond.asp" method="get">
Fill Out This Form For Us:<p>
Last Name -> <Input NAME="NameLast" size ="10"><br>
Country -> <Input NAME="Country" value="USA" size="10"><br>
State -> <Input NAME="State" MaxLength="2" size="2"><br>
<Input type="submit" value="Give me your data!">
<hr></form>
</body></html>


filename=/learn/test/formtextboxrespond.asp
<Test Script Below>

<html><head>
<title>FormTextBoxRespond.asp</title>
</head><body bgcolor="#FFFFFF">
<%
lname=request.querystring("namelast")
cty=request.querystring("country")
st=request.querystring("state")

response.write lname & "<br>"
response.write cty & "<br>"
response.write st & "<br>"%>
</body></html>



Forms - Radio Buttons  

All of your user input objects in a form must have their own unique name which will be the label that the browser will assign to them when passing the data to ASP. The exceptions are radio buttons. Since only one piece of information will be passed to ASP from a set of radio buttons, they all get the same name. HTML requires that one of the buttons is selected by default, the one indicated by the CHECKED command. It is important to understand that the browser will send back to ASP the name and the value of the one button which is selected by the user. The browser will NOT send back the text which is associated with the button. For the example above, if the user checked on the button with the text New York City, then ASP would receive City=NY.

filename=/learn/test/FormRadio.asp
<Test Script Below>

<html><head>
<TITLE>formRadio.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<form action="FormRadiorespond.asp" method="post">
<p><b>Radio Buttons </b> example</p>
<p>Which Regional Office will you be visiting?</p>
<input TYPE="radio" NAME="City" VALUE="NY">New York City
<input TYPE="radio" NAME="City" VALUE="LA">Los Angeles
<input TYPE="radio" NAME="City" VALUE="SV" CHECKED>Savannah
<br><input type="submit" value="choose a city">
</form>
</body></html>


The responder looks like:

filename=/learn/test/FormRadiorespond.asp
<Test Script Below>

<html><head>
<TITLE>formradiorespond.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<%myCity = request.form("City")
Select Case ucase(MyCity)
case "NY"
response.write "New York meeting is on Jan 3"
case "LA"
response.write "LA meeting meeting is on Jan 15"
case "SV"
response.write "Savannah meeting is on Jan 20"
End Select%>
</body>
</html>


Forms - Text Area

Multi-line text boxes are created using the TEXTAREA command as follows:

<TEXTAREA NAME="UserComments" ROWS=5 COLS=50>
... default text is typed here
</TEXTAREA>

<Test Script Below>

<html><head>
<TITLE>formTextArea.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<form action="FormTextAreaRespond.asp" method="post">
<p>TextArea Example</p>
<p>Please type your special shipping comments:</p>
<TEXTAREA NAME="shippingComments" ROWS="5" COLS="50">
shipping comments go here
</textarea>
<p><input type=submit value="send in comments!">
</form>
</body></html>


The responder to the form will look like this:

filename=/learn/test/FormTextArearespond.asp
<Test Script Below>

<html><head>
<TITLE>formTextArearespond.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<%
comm=request.form("shippingcomments")
response.write comm
%>
<hr>
</body></html>

No comments:

Post a Comment