The most important HTML element for our game is the form tag. The FORM is basically an HTML element that allows you to pass information from your webpage to the server. Note that you can have more than 1 form on a page! Each form has 2 main parts:
- form declaration - this begins and ends with the <form> </form> tags, and tells your webpage that the information between the two tags will be sent to the server. You also specify where the information will be sent to and how it will be sent. You can include many different kinds of inputs between these two tags. For an explanation of the <form> tag, visit the w3schools reference
Within your form, you can pass information to the webserver using the <input> element in several different ways. For information on some of the different types of Input types you might include in your page, visit the w3schools reference.
- text - passes basic information to the server. This passes a user-enteredline It might include an email address, a name, a place, but because it can be almost anything it might be as useful for our game, where maybe we want to restrict the user to specific inputs. For example if the user wants to go to the library, it's probably best not to use this to obtain that information. What if they enter in "libraryu" or "libary" (spelled wrong)...your program might understand that. That's why some of the other options might be better. This can be good for output. For an example of how this element has been used to display output only (and not receive input) visit http://sdssinfotech.netne.net.
- radio boxes - when you want the user to choose only one of a certain number of choices.
- check boxes - when you want the user to be able to make several yes/no choices
- hidden - when you want to pass specific information to the server, but you don't necessarily want it to be displayed on the page.
Another useful way to send information is to use the <select> </select> element. This creates a drop down list and you can choose one of the options.
Alternatives to the Submit Button
Imagine you want to have a drop down menu with different places to visit. You could have the user choose the option, and then press the submit button to go there. Alternatively, you could have the user choose an option from the drop down menu, and as soon as it is selected, the user could go to that location. This is sometimes preferable, especially if you want to have the form on your page handle things within the page.