Electric Type

Multimedia

About Us

News

Help

Your First Database
Lesson 3

by Jay Greenspan

Page 4 — Working with Forms

Usually, when you create SQL statements, you make use ofvariables within the statement. For instance, if someone used the site and entered a first name, last name, and email address into thedatabase, you'd want to retrieve this information with a query. Armed withthat information, you would thensend the following query to the database:

SELECT fname, lname, FROM Clients WHERE email =variableholdingemail

But how are you going to get that variable? You're going to use HTML formsanda couple lines of VBScript.

For the handful of you who've never created a form in HTML, rest assured - they're super easy. Take a look at the HTML that creates a simple input text box.

Here's the code:

<form action="nextpage.html" method="GET" name="myform">	<input type="Text" name="thebox" align="TOP" size="25"><br>	<input type="Submit" value="Take A Look" align="MIDDLE"></form>

And here's the form:


Enter whatever text you want into the box and pressthe button. When a new page appears, take a close look atthe URL in your browser. Once you're done with the examination, come onback here.

Welcome back. I'm assuming you noticed two things. First, the URL of thepage that loaded matches the action attribute of the opening formtag.Second, the last part of the URL began with a question mark, which wasfollowed bythebox=whatever you typed. Being the astute observer I know youare, you see that Thebox matches the Name attribute of the input tag.

The stuff that follows the question mark is known as the querystring.And the text appears there in name=value pairs. Additional name=value pairswill be separated by an ampersand.

You've seen the textbox in action. Let's take a look at a couple other formelements that will come in handy as you build your data-driven site: hiddenand checkbox.

Here's the code:

<form action="nextpage.html" method="get" name="form2">	<input type="hidden" name="hiddenvalue" value="hiddenstuff"><br>	<input type="Checkbox" name="check1" value="yup"> Checkbox here<br>	<input type="Submit" value="Take A Look" align="MIDDLE"></form>

And here's the form:


Checkbox here

Notice that after you click Take A Look, the name and value of thehidden element will be passed to thequerystring, whether you've checked the box or not. If the checkbox isclicked, however, the value of thecheckbox is passed on to the querystring.

Let's look at radio buttons and thedropdown box. With radio buttons, only one of the values can be selected.You can add as many buttons to a list of potential values as you like, justmake sure the name attribute matches in all of them. If you wantone of the values to be pre-selected, insert Checked into the tag.With a dropdown box, the text that appears to the user hasnothing to do with the value passed to the querystring. As always, it's thevalue attribute that gets passed.

The code:

<form action="nextpage.html" method="get" name="form3">	<input type="radio" name="radios" value="radio1" checked><b>This is radio1</b><br>	<input type="radio" name="radios" value="radio2"> <b>This isradio2</b><br>	<select name="dropdown">		<option value="1">drop-down list 1</option>		<option value="2">drop-down list 2</option>	</select>	<input type="Submit" value="Take A Look" align="MIDDLE"></form>

The form:

This isradio1
This isradio2

One more word on forms: In the opening form tag, you have twochoices for the method attribute - Get, which we've been using inthe above examples, and Post. When the method is Get, the name=valuepairs will be passed to the querystring, as you've seen. If, however, youchoose Post, the information will be sent to the server fromwithin the HTTP header. You can still access the information (as I'm goingto show on the next page), but your user won't be able to see the value.More important, the user won't be able to bookmark the page.

And so ends the crash course in forms. Now back to SQL.

next page»


Lesson 1  

Lesson 2  

Lesson 3  

Lesson 4  

Authoring Home  

User Blogs

Screen Shots

Latest Updates

Contact Us

Valid HTML 4.01!
Valid CSS!

Breadcrumb

© ElectricType
Maintained by My-Hosts.com
Site map | Copyright | Disclaimer
Privacy policy | Acceptable Use Policy
Legal information.