1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| <!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<!-- cache-control avec max-age=60 pour le développement uniquement -->
<meta http-equiv="cache-control" content="public, max-age=60">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta name="author" content="Daniel Hagnoul">
<title>test</title>
<style>
*,
*:after,
*:before {
box-sizing: border-box;
}
/* code du test */
#dataIndividu {
width: 22rem;
}
#dataIndividu > input {
display: block;
width: 18rem;
}
/* fin code du test */
</style>
<script>
'use strict';
document.addEventListener( "DOMContentLoaded", ev => {
// le DOM est construit, la page web n'est pas visible
// code du test
// fin code du test
}, false );
window.addEventListener( "load", ev => {
// le DOM est construit et la page web est visible
// code du test
document.querySelector( "#formIndividu" ).addEventListener( "submit", ev => {
ev.stopPropagation();
ev.preventDefault();
const
dataIndividu = {},
inputs = Array.from( document.querySelectorAll( "#dataIndividu > input" ) );
for ( const input of inputs ){
dataIndividu[ input.getAttribute( "placeHolder" ) ] = input.getAttribute( "data-base" );
}
const strJSON = JSON.stringify( dataIndividu );
// debug, console, touche F12
console.log( strJSON );
}, false );
// fin code du test
}, false );
</script>
</head>
<body>
<main>
<form id="formIndividu">
<fieldset id="dataIndividu">
<legend>Individu</legend>
<input type="text" placeHolder="nom" data-base="Dupond">
<input type="text" placeHolder="prénom" data-base="Henri">
<input type="text" placeHolder="prénom enfant 1" data-base="Serge">
<input type="text" placeHolder="prénom enfant 2" data-base="Luc">
<input type="text" placeHolder="code postal" data-base="59300">
<input type="text" placeHolder="ville" data-base="Villerasée">
</fieldset>
<input type="submit">
</form>
</main>
</body>
</html> |
Partager