30
Introduction To HTML Introduction To HTML Form Inputs Form Inputs Written By George Gimian Written By George Gimian

Introduction To HTML Form Inputs Written By George Gimian

Embed Size (px)

Citation preview

Page 1: Introduction To HTML Form Inputs Written By George Gimian

Introduction To HTML Introduction To HTML Form InputsForm Inputs

Written By George Gimian Written By George Gimian

Page 2: Introduction To HTML Form Inputs Written By George Gimian

FormsForms

Forms are used to make web Forms are used to make web pages more interactivepages more interactive

They allows us to collect They allows us to collect information from the web pageinformation from the web page

The information is collected via The information is collected via input text boxes or checkboxes or input text boxes or checkboxes or radio buttons as we will learn radio buttons as we will learn todaytoday

Page 3: Introduction To HTML Form Inputs Written By George Gimian

FormsForms

The basic form structure is as The basic form structure is as followsfollows<form><form>

content content

</form></form> As you can see it takes the form As you can see it takes the form

of any standard html tag.of any standard html tag.

Page 4: Introduction To HTML Form Inputs Written By George Gimian

Forms – Attributes Forms – Attributes

Forms like every other tag has Forms like every other tag has attributes:attributes:– Action – this is used to tell a web page Action – this is used to tell a web page

do this when I press the button on this do this when I press the button on this pagepage

– Method – Get (data sent to server Method – Get (data sent to server appended) or Post (transaction body) appended) or Post (transaction body)

– Target – where is the information Target – where is the information going to be displayedgoing to be displayed

Page 5: Introduction To HTML Form Inputs Written By George Gimian

Forms – ButtonsForms – Buttons

To create a button on your page To create a button on your page which works in contribution to which works in contribution to your form simply:your form simply:

<form><form>

<input type=“button” <input type=“button” value=“Press Me”>value=“Press Me”>

</form></form>

Page 6: Introduction To HTML Form Inputs Written By George Gimian

Forms – Buttons Forms – Buttons

Page 7: Introduction To HTML Form Inputs Written By George Gimian

Forms – ButtonsForms – Buttons

If you have created an action for a If you have created an action for a form though you should use a form though you should use a submit button to send your submit button to send your information via email or via information via email or via another file. Or a reset button to another file. Or a reset button to reset the page.reset the page.

<form><form>

<input type="submit" value="Send"><input type="submit" value="Send">

<input type="reset" value="Reset"><input type="reset" value="Reset">

</form></form>

Page 8: Introduction To HTML Form Inputs Written By George Gimian

Forms – Inputs (text)Forms – Inputs (text)

Adding an input to the form is Adding an input to the form is also very simple. You simply say:also very simple. You simply say:<form><form>

<input type=“text” /><input type=“text” />

</form></form>

This tells the browserTo expect input This tells the browser

The type of input to expect

Because the input tag Doesn’t have a closingTag you must put a spaceAnd backslash to make it XHTML compatible

Page 9: Introduction To HTML Form Inputs Written By George Gimian

Forms – Inputs (text)Forms – Inputs (text)

Adding an input to the form is Adding an input to the form is also very simple. You simply say:also very simple. You simply say:<form><form>

<input type=“text” /><input type=“text” />

</form></form>

Text can have attributes:-name-size-maxlength

Page 10: Introduction To HTML Form Inputs Written By George Gimian

Forms – Input (text) Forms – Input (text) ExampleExample For example:For example:

<form><form>Please enter your first name: <input type=“text” Please enter your first name: <input type=“text” /><br />/><br />

Please enter your surname: <input type=“text” /><br Please enter your surname: <input type=“text” /><br />/>

</form></form>

Page 11: Introduction To HTML Form Inputs Written By George Gimian

Forms – Input (text) Forms – Input (text) ExampleExample

Page 12: Introduction To HTML Form Inputs Written By George Gimian

Forms – Input (text)Forms – Input (text)

What about if I want some What about if I want some information in the text box initially?information in the text box initially?

Well all we simply do is use the Well all we simply do is use the value attribute of the input tag!value attribute of the input tag!

Eg:Eg:

<input type=“text” name=“Firstname” value=“Please <input type=“text” name=“Firstname” value=“Please enter your first name” />enter your first name” />

Page 13: Introduction To HTML Form Inputs Written By George Gimian

Forms – Input (text) Forms – Input (text) ExampleExample

Page 14: Introduction To HTML Form Inputs Written By George Gimian

Forms – Input Forms – Input (Password)(Password) What happens if you want to What happens if you want to

enter a password into a field enter a password into a field though? You don’t want everyone though? You don’t want everyone to see youre password!to see youre password!

Well there is a solution. You Well there is a solution. You simply use a password fieldsimply use a password field

<input type=“password” /><input type=“password” />

Page 15: Introduction To HTML Form Inputs Written By George Gimian

Forms – Input Forms – Input (Password) - Example(Password) - Example

Page 16: Introduction To HTML Form Inputs Written By George Gimian

Forms – Multiple-Line Forms – Multiple-Line Text AreasText Areas What if you would like a multiple What if you would like a multiple

line input? Well its simple you line input? Well its simple you simply use the following tag:simply use the following tag:

<textarea name=“Comments”><textarea name=“Comments”>

</textarea></textarea>

With this tag it has two main With this tag it has two main attributes:attributes:– Rows – the height of the text boxRows – the height of the text box– Cols – the width of the text boxCols – the width of the text box

Page 17: Introduction To HTML Form Inputs Written By George Gimian

Forms – Multiple-Line Forms – Multiple-Line Text Areas ExampleText Areas Example

Page 18: Introduction To HTML Form Inputs Written By George Gimian

Forms – Radio ButtonsForms – Radio Buttons

How can we make an easy solution How can we make an easy solution were a user can select from one were a user can select from one option only within a selection? option only within a selection? Simple using a Radio Button, Simple using a Radio Button, which is another input type.which is another input type.

A Radio button list needs to have A Radio button list needs to have the same name to be part of a the same name to be part of a selection listselection list

Page 19: Introduction To HTML Form Inputs Written By George Gimian

Forms – Radio ButtonsForms – Radio Buttons

Eg:Eg:<form><form>

Please select from the following:Please select from the following:

<input type=“radio” name=“r1” <input type=“radio” name=“r1” value=“Selection 1”> Selection 1 <br />value=“Selection 1”> Selection 1 <br /><input type=“radio” name=“r1” <input type=“radio” name=“r1” value=“Selection 2”> Selection 2 <br />value=“Selection 2”> Selection 2 <br /> <input type=“radio” name=“r1” <input type=“radio” name=“r1” value=“Selection 3”> Selection 3 <br />value=“Selection 3”> Selection 3 <br />

</form></form>

Page 20: Introduction To HTML Form Inputs Written By George Gimian

Forms – Radio ButtonsForms – Radio Buttons

Page 21: Introduction To HTML Form Inputs Written By George Gimian

Forms – Check BoxesForms – Check Boxes

How can we make an easy How can we make an easy solution were a user can select solution were a user can select more than one option within a more than one option within a selection? Simple using a Check selection? Simple using a Check Box, which is another input type.Box, which is another input type.

A Check Box needs to have the A Check Box needs to have the same name to be part of a same name to be part of a selection listselection list

Page 22: Introduction To HTML Form Inputs Written By George Gimian

Forms – Check BoxesForms – Check Boxes

Eg:Eg:<form><form>

Please select from the following:Please select from the following:

<input type=“checkbox” name=“c1” <input type=“checkbox” name=“c1” value=“Selection 1”> Selection 1 <br />value=“Selection 1”> Selection 1 <br /><input type=“checkbox” name=“c1” <input type=“checkbox” name=“c1” value=“Selection 2”> Selection 2 <br />value=“Selection 2”> Selection 2 <br /> <input type=“checkbox” name=“c1” <input type=“checkbox” name=“c1” value=“Selection 3”> Selection 3 <br />value=“Selection 3”> Selection 3 <br />

</form></form>

Page 23: Introduction To HTML Form Inputs Written By George Gimian

Forms – Check BoxesForms – Check Boxes

Page 24: Introduction To HTML Form Inputs Written By George Gimian

Forms – Select MenusForms – Select Menus

How can we make an easy How can we make an easy solution were a user can select solution were a user can select one option within a drop down one option within a drop down selection? Simple using a selection? Simple using a Selection Menu, which is another Selection Menu, which is another input type.input type.

Page 25: Introduction To HTML Form Inputs Written By George Gimian

Forms – Select MenusForms – Select Menus

Eg:Eg:<form><form>

Please select a colour:Please select a colour:

<select name=“Colour” size=“3”><select name=“Colour” size=“3”>

<option value=“blue”>blue</option><option value=“blue”>blue</option>

<option value=“red”>red</option><option value=“red”>red</option>

<option value=“pink”>pink</option><option value=“pink”>pink</option>

<option value=“white”>white</option><option value=“white”>white</option>

</select></select>

</form></form>

Page 26: Introduction To HTML Form Inputs Written By George Gimian

Forms – Select MenusForms – Select Menus

Page 27: Introduction To HTML Form Inputs Written By George Gimian

Forms – Select MenusForms – Select Menus

Eg:Eg:<form><form>

Please select a colour:Please select a colour:

<select name=“Colour” size=“1”><select name=“Colour” size=“1”>

<option value=“blue”>blue</option><option value=“blue”>blue</option>

<option value=“red”>red</option><option value=“red”>red</option>

<option value=“pink”>pink</option><option value=“pink”>pink</option>

<option value=“white”>white</option><option value=“white”>white</option>

</select></select>

</form></form>

Page 28: Introduction To HTML Form Inputs Written By George Gimian

Forms – Select MenusForms – Select Menus

Page 29: Introduction To HTML Form Inputs Written By George Gimian

Forms – The Forms – The PossibilitiesPossibilities Forms have endless possibilities which Forms have endless possibilities which

are detailed on w3schools:are detailed on w3schools:– SubmenusSubmenus– File uploadsFile uploads– Hidden fieldsHidden fields– ButtonsButtons– etcetc

Page 30: Introduction To HTML Form Inputs Written By George Gimian

Forms – SubmenusForms – Submenus

<select name=“TimeDay”><select name=“TimeDay”>

<optgroup label=“Monday”><optgroup label=“Monday”>

<option value=“Monday AM”>Monday morning</option><option value=“Monday AM”>Monday morning</option>

<option value=“Monday PM”>Monday afternoon</option><option value=“Monday PM”>Monday afternoon</option>

</optgroup></optgroup>

<optgroup label=“Tuesday”><optgroup label=“Tuesday”>

<option value=“Tuesday AM”>Tuesday morning</option><option value=“Tuesday AM”>Tuesday morning</option>

<option value=“Tuesday PM”>Tuesday afternoon</option><option value=“Tuesday PM”>Tuesday afternoon</option>

</optgroup></optgroup>

</select></select>