Exemples Cours

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Les éléments du formulaire

1. <input>

<label for="fname">First name:</label>


<input type="text" id="fname" name="fname">

2. <select>

<label for="cars">Choose a car:</label>


<select id="cars" name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<label for="cars">Choose a car:</label>
<select id="cars" name="cars" size="3">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<label for="cars">Choose a car:</label>
<select id="cars" name="cars" size="4" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>

3. <textarea>

<textarea name="message" rows="10" cols="30">


The cat was playing in the garden.
</textarea>

4. <button>

<button type="button" onclick="alert('Hello


World!')">Click Me!</button>
5. <fieldset>

<form action="/action_page.php">
<fieldset>
<legend>Personalia:</legend>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John
"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"
><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>

6. <datalist>

<form action="/action_page.php">
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>

7. <output>

<form action="/action_page.php"
oninput="x.value=parseInt(a.value)+parseInt(b.value)">
0
<input type="range" id="a" name="a" value="50">
100 +
<input type="number" id="b" name="b" value="50">
=
<output name="x" for="a b"></output>
<br><br>
<input type="submit">
</form>
Les différents types d’input
Input Type Text

<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>

Input Type Password

<form>
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="pwd">Password:</label><br>
<input type="password" id="pwd" name="pwd">
</form>

Input Type Submit

<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John">
<br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><
br><br>
<input type="submit" value="Submit">
</form>

Input Type Reset

<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John">
<br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><
br><br>
<input type="submit" value="Submit">
<input type="reset">
</form>

Input Type Radio

<form>
<input type="radio" id="male" name="gender" value="male"
>
<label for="male">Male</label><br>
<input type="radio" id="female" name="gender" value="fem
ale">
<label for="female">Female</label><br>
<input type="radio" id="other" name="gender" value="othe
r">
<label for="other">Other</label>
</form>

Input Type Checkbox

<form>
<input type="checkbox" id="vehicle1" name="vehicle1" val
ue="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" val
ue="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" val
ue="Boat">
<label for="vehicle3"> I have a boat</label>
</form>

Input Type Button

<input type="button" onclick="alert('Hello


World!')" value="Click Me!">

Input Type Color

<form>
<label for="favcolor">Select your favorite
color:</label>
<input type="color" id="favcolor" name="favcolor">
</form>

Input Type Date

<form>
<label for="birthday">Birthday:</label>
<input type="date" id="birthday" name="birthday">
</form>

You can also use the min and max attributes to add restrictions to
dates:

<form>
<label for="datemax">Enter a date before 1980-01-
01:</label>
<input type="date" id="datemax" name="datemax" max="1979
-12-31"><br><br>
<label for="datemin">Enter a date after 2000-01-
01:</label>
<input type="date" id="datemin" name="datemin" min="2000
-01-02">
</form>

Input Type Email

<form>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email">
</form>

Input Type File

<form>
<label for="myfile">Select a file:</label>
<input type="file" id="myfile" name="myfile">
</form>

Input Type Month

<form>
<label for="bdaymonth">Birthday (month and
year):</label>
<input type="month" id="bdaymonth" name="bdaymonth">
</form>

Input Type Number

<form>
<label for="quantity">Quantity (between 1 and
5):</label>
<input type="number" id="quantity" name="quantity" min="
1" max="5">
</form>

Différence entre GET et POST

GET POST

Visibilité Visible pour l’utilisateur dans le Invisible pour l’utilisateur


champ d’adresse

Marque-page et historique de Les paramètres de l’URL sont L’URL est enregistrée sans paramètres
navigation stockés en même temps que URL.
l’URL.

Cache et fichier log du Les paramètres de l’URL sont Les paramètres de l’URL ne sont pas
serveur stockés sans chiffrement enregistrés automatiquement.

Comportement lors de Les paramètres de l’URL ne sont Le navigateur avertit que les données
l’actualisation du navigateur / pas envoyés à nouveau. du formulaire doivent être renvoyées.
Bouton « précédent »

Type de données Caractères ASCII uniquement. Caractères ASCII mais également


données binaires.

Longueur des données Limitée - longueur maximale de Illimitée.


l’URL à 2 048 caractères.

You might also like