Create a page that contains a form that lets the user enter their email address
ID: 3539680 • Letter: C
Question
Create a page that contains a form that lets the user enter their email address as the user and a password. When the user submits the form, if the user filled out a username and password (so they are not null) write the values to a cookie. If there is no value entered in either field, write out an alert message with instructions to the user to complete the form.
Also in the same page, include a button that when clicked, will display the value of the cookie in the web page. (such as in a label control etc.)
Explanation / Answer
<FORM METHOD="Get" ACTION="Profile.asp">
<INPUT TYPE="Text" NAME="FirstName">
<INPUT TYPE="Text" NAME="LastName">
<INPUT TYPE="Text" NAME="Age">
<INPUT TYPE="Hidden" NAME="UserStatus" VALUE="New">
<INPUT TYPE="Submit" VALUE="Enter">
</FORM>
HTML forms, the most common method for gathering Web-based information, consist of arrangements of special HTML tags that render user interface elements on a Web page. Text boxes, buttons, and check boxes are examples of elements that enable users to interact with a Web page and submit information to a Web server.
For example, the following HTML tags generate a form where a user can enter their first name, last name, and age, and includes a button for submitting information to a Web server. The form also contains an hidden input tag (not displayed by the Web browser) that you can use to pass additional information to a Web server.
buttons:
Forms can contain many different kinds of elements to help your users enter data. In this example, there are five input form elements called buttons. There are many types of buttons including RADIO buttons, SUBMIT buttons, RESET buttons, CHECKBOX buttons, and TEXT buttons.
After the user enters information in a form, the information needs to be sent to your Web application. When a user clicks the button labeled "Submit" in your Web page, the form data is sent from the client to the Web page that is listed in the ACTION element of the form tag. This Web page doesn't need to be the same as the calling page. In this example, the Web page listed in the ACTION element is the same as the calling page, which eliminates the need to call another page.
In this example, METHOD=" POST" is used to send data from the Web client's browser to the Web server. When you use METHOD=" POST" in a form, the user data ends up in the Form collection of the Request object.
Copy and paste the following code in your text editor, and save the file as Button.asp in the x:InetpubWwwrootTutorial directory. View the example with your browser by typing http://localhost/Tutorial/Button.asp in the address bar.
<%@ Language= "VBScript" %>
<html>
<head>
<title>Button Form</title>
</head>
<body>
<font face="MS Gothic">
<FORM NAME="Button Example" METHOD="POST" ACTION="button.asp">
<H3>Computer Programming Experience:</H3>
<p>
<INPUT TYPE="RADIO" NAME= "choice" VALUE="Less than 1"> Less than 1 year.<BR>
<INPUT TYPE="RADIO" NAME= "choice" VALUE="1 to 5"> 1-5 years.<BR>
<INPUT TYPE="RADIO" NAME= "choice" VALUE="More than 5"> More than 5 years.<BR>
</p>
<p>
<INPUT TYPE="SUBMIT" VALUE="Submit">
<INPUT TYPE="RESET" VALUE="Clear Form">
</p>
</form>
<%
'Check to see if input has already been entered.
dim strChoice
strChoice = Server.HTMLEncode(Request.Form("choice"))
If "" = strChoice Then
Response.Write "<P>(No input yet.)</P>"
Else
Response.Write "<P>Your last choice was <B>" & strChoice & "</B></P>"
End If
%>
</font>
</body>
</html>
In the browser, you should see the following:
Computer Programming Experience:
Radio Button
Less than 1 year.
Radio Button
1-5 years.
Radio Button
More than 5 years. (No input yet.)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.