Forms in HTML

In this tutorial I'm going to show you how to create forms, which are a great way to collect feedback from your site or if your creating a guestbook. FYI, HTML on it's own cannot create these, this is just the client side part (the forms), creating feedback forms or a guestbook would need to help of a server side language.

To begin, we need to open the form tag and give our entire form a name, like this;

<form name="form_one">

Now we can add our input boxes / checkboxes / radio buttons ect, for people to add their data. Firstly, an input box for users to add their name.

Name: <input type="text" name="name" size="20">

The above code would give us the following results;

Name:

It is always wise to give all your form elements names that are relevant so you don't get muddled up when using forms on a larger scale. Now the code above would give us an input box called name that is size 20.

Next, for an input box for users to enter their email addresses, we can use the same code as before. After that, lets add a big textarea so users can write in comments.

Comments:
<textarea name="comments" rows="7" cols="50"></textarea>

Now this would give us a textarea, 7 rows (top - bottom) and 50 cols (left to right) which looks like this.

Comments:

OK, now we have input boxes and a comment textarea, how about a set of radio buttons?

<p>Rate This Out of 5</p>
5 - <input type="radio" name="rate" value="5"><br>
4 - <input type="radio" name="rate" value="4"><br>
3 - <input type="radio" name="rate" value="3"><br>
2 - <input type="radio" name="rate" value="2"><br>
1 - <input type="radio" name="rate" value="1"><br>

Now you will notice we have type="radio" which tells the browser we want radio buttons, the name is again meaningful but this time we have a new attribute value. Value simple means what value that particular radio button has, each must be different otherwise you will end up with incorrect feedback. This code gives the following results;

Rate This Out of 5

5 -
4 -
3 -
2 -
1 -

And now we have a set of radio buttons, now how about an select group box with a drop down menu

Where are you from?

This is easier to make than you might think, here is the code;

Where are you from?
<select name="location">
<option value="uk">United Kingdom</option>
<option value="us">America</option>
<option value="france">France</option>
<option value="germany">Germany</option>
<option value="australia">Australia</option>
</select>

Now to finish we will need a reset and submit button, then we can close our form and finish up for the day.

 

Here are our two buttons, reset and submit should be the only two buttons you will need but it's not hard to make others, here's how to make these.

<input type="reset" name="reset" value="reset" />
<input type="button" name="submit" value="submit" />

And now there's nothing left but to close our form with the </form> tag, easy! Now how about putting all of this together.

<form name="form_one">
Name: <input type="text" name="name" size="20">
EMail: <input type="text" name="email" size="20">

Where are you from?
<select name="location">
<option value="uk">United Kingdom</option>
<option value="us">America</option>
<option value="france">France</option>
<option value="germany">Germany</option>
<option value="australia">Australia</option>
</select>

Comments:
<textarea name="comments" rows="7" cols="50"></textarea>

<p>Rate This Out of 5</p>
5 - <input type="radio" name="rate" value="5"><br>
4 - <input type="radio" name="rate" value="4"><br>
3 - <input type="radio" name="rate" value="3"><br>
2 - <input type="radio" name="rate" value="2"><br>
1 - <input type="radio" name="rate" value="1"><br>

<input type="reset" name="reset" value="reset" />
<input type="button" name="submit" value="submit" />

</form>

And all this would give us a nice form like so.

Name:

EMail:

Where are you from?

Rate This Out of 5

5 -
4 -
3 -
2 -
1 -

Comments:

If you enter some data into any of the boxes and then press the RESET button you will notice that all currently entered data gets removed and all the boxes are emptied, the SUBMIT button won't do anything for the moment because it hasn't got any purpose (until you give it one using a server side language).


Close    To Top
  • Prev Article-Web Design:
  • Next Article-Web Design:
  • Now: Tutorial for Web and Software Design > Web Design > HTMLCSS > Web Design Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction