Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<header>
    <nav>
        <span><a href="index.html"></a></span>
    </nav>
</header>

<main>

    <div class="container">
        <h3> Formulaire de réservation de vols </h3><br>
        <form id="flightResa" method="POST" onsubmit="return searchFlights(flightResa)">
            <div class="flex">
                <label for="flightFrom">Aéroport de départ : </label>
                <input type="text" name="depart" id="autocomplete-airport-1" class="flight" required
                    onchange="checkDistance(this)">
                <label for="flightTo">Aéroport d'arrivée : </label>
                <input type="text" name="arrivee" id="autocomplete-airport-2" class="flight" required
                    onchange="checkDistance(this)">
                <strong id="distance" class="">...</strong>
                <strong>Km</strong>
            </div>
            <div class="flex">
                <label for="depart">Date de départ : </label>
                <input type="date" name="date" id="depart" class="flight" placeholder="JJ/MM/AAAA" max="2025-12-31"
                    required>
                <label for="retour">Date de retour : </label>
                <input type="date" name="date" id="retour" class="flight" placeholder="JJ/MM/AAAA" required>
            </div>
            <div class="flex">
                <label for="adulte">Nombre d'adultes (12 ans et +)</label>
                <input type="number" name="passager" id="adulte" class="nbr" min="0" value="0" required>
                <label for="enfant">Nombre d'enfants (- de 12 ans)</label>
                <input type="number" name="passager" id="enfant" class="nbr" min="0" value="0" required>
            </div>
            <div class="flex">
                <label for="eco">Classe éco</label>
                <input type="radio" name="classe" id="eco" class="choixClasse" checked>
                <label for="affaire">Classe affaire</label>
                <input type="radio" name="classe" id="affaire" class="choixClasse">
                <label for="premiere">Première classe</label>
                <input type="radio" name="classe" id="premiere" class="choixClasse">
            </div>
            <div class="flex" id="divSearch">
                <input type="submit" value="Rechercher" class="flight" id="search">
            </div>
            <div class="reset">
                <input type="reset" value="Effacer" class="flight" id="reset">
            </div>
        </form>
    </div>

    <div class="container" id="hide">

        <form action="" method="post">
            <div class="flex">
                <label for="recap" class="recap">Récapitulatif du vol et des coûts</label>

            </div>
            <div class="flex">
                <textarea name="Récapitulatif" class="recap" id="recap" cols="100" rows="10" disabled>

                    </textarea>
            </div>
        </form>

    </div>



</main>

<footer>


    <p>© 2019 Mathieu François</p>

<script src="https://cdn.jsdelivr.net/npm/airport-autocomplete-js@latest/dist/index.browser.min.js"></script>
    <script>
        AirportInput("autocomplete-airport-1");
        var options = {
            formatting: `<div class="$(unique-result)"
                     single-result" 
                     data-index="$(i)"> 
                   $(IATA) </div>`
        };
        AirportInput("autocomplete-airport-2", options);
        function distance(lat1, lon1, lat2, lon2) {
            var R = 6371e3; // metres
            lat1 = parseFloat(lat1)
            lat2 = parseFloat(lat2)
            lon1 = parseFloat(lon1)
            lon2 = parseFloat(lon2)
            var f1 = lat1.toRadians();
            var f2 = lat2.toRadians();
            var df = (lat2 - lat1).toRadians();
            var dl = (lon2 - lon1).toRadians();
            var a = Math.sin(df / 2) * Math.sin(df / 2) +
                Math.cos(f1) * Math.cos(f2) *
                Math.sin(dl / 2) * Math.sin(dl / 2);
            var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
            var d = R * c;
            return d;
        }
        if (typeof (Number.prototype.toRadians) === "undefined") {
            Number.prototype.toRadians = function () {
                return this * Math.PI / 180;
            }
        }
        function checkInputData(id) {
            var realId = "autocomplete-airport-" + id
            return ([document.getElementById(realId).getAttribute("data-lat"), document.getElementById(realId).getAttribute(
                "data-lon")])
        }
        function checkDistance(self) {
            console.log("Input changed: " + self["id"])
            setTimeout(function () {
                console.log(self.getAttribute("data-lon"))
                var idChanged = self["id"].slice(-1)
                console.log(checkInputData(1))
                console.log(checkInputData(2))
                if (checkInputData(1)[0] && checkInputData(2)[0]) {
                    var dst = distance(...checkInputData(1), ...
                        checkInputData(2)) / 1000;
                    document.getElementById("distance").innerHTML = parseInt(dst);
                }
            }, 200)
        }
    </script>
</footer>
              
            
!

CSS

              
                /* ===================================
		General
==================================== */
* {
	box-sizing: border-box;
  font-family: 'Open Sans', sans-serif;
}

body {
	margin: 0;
  background-color: #ffffff;
}

a {
	text-decoration: none;
}

p,
ul li,
ol li {
	font-size: 18px;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Russo One', sans-serif;
}



/* ===================================
		Navigation bar
==================================== */
nav {
	background-color: #ffffff;
	display: flex;
	flex-flow: row nowrap;
	height: 100px;
  top: 0;
  position: fixed;
	width: 100%;
  border-bottom: 5px solid #0190b8;
}

nav span {
	color: #0190b8;
	height: 100%;
	font-size: 40px;
	line-height: 100px;
	padding-left: 40px;
	width: 60%;
}

nav span a {
	color: #0190b8;
}

img {
	height: 90%;
	width: 280px;
}

/* ===================================
		Main
==================================== */
main {
  margin-top: 130px;
}

h3 {
	color: #0190b8;
	font-size: 40px;
	text-align: center;
	margin: 15px;
}

.container {
	margin: 0 auto;
	width: 90%;
	box-shadow: 3px 5px 10px #0190b8;
}

.flex {
		display: flex;
		justify-content: space-evenly;
		margin-bottom: 30px;
}

.flexPaypal {
	display: flex;
	justify-content: center;
}

.reset {
	margin-left: 20px;
}

.flight {
	width: 200px;
	height: 30px;
	border-radius: 10px 3px;
	margin-bottom: 50px;
}

.nbr {
	width: 60px;
	height: 30px;
	border-radius: 15px 3px;
	margin-bottom: 50px;
}

.choixClasse {
	border-radius: 15px 3px;
	margin-bottom: 50px;
}

#search {
	background-color: rgb(0, 140, 255);
	color: #ffffff;
	width: 400px;
	height: 50px;
	margin-bottom: 1px;
	font-size: 25px;

}

#divSearch {
	margin-bottom: 2px;
}

.recap {
	margin-top: 10px;
	margin-bottom: 20px;
}

#recap {
	font-size: 15px;
}
/* ===================================
		Footer
==================================== */
p {
	text-align: center;
}
              
            
!

JS

              
                //==================================On Open==============================
document.getElementById("recap").innerHTML = "Voici un récapitulatif de votre dernière commande : " + localStorage.getItem("recapStore");
var date = new Date();
var day = date.getDate();
var dayReturn = date.getDate() + 1;
var month = date.getMonth() + 1;
var year = date.getFullYear();

var input1 = "";
var startDateEntered = "";
 
document.getElementById("depart").min = year + "-0" + month + "-" + day;
document.getElementById("retour").min = year + "-0" + month + "-" + dayReturn;

document.getElementById("depart").addEventListener("change", function () {
    input1 = this.value;
    startDateEntered = new Date(input1);
    dayReturn = startDateEntered.getDate() + 1;
    month = startDateEntered.getMonth() + 1;
    year = startDateEntered.getFullYear();

    document.getElementById("retour").min = year + "-0" + month + "-" + dayReturn;
});

//=======================================================================


//==============================On submit================================
function searchFlights(form) {
    var dateDepart = new Date(document.getElementById("depart").value);
    var dateRetour = new Date(document.getElementById("retour").value);
    var distance = parseInt(document.getElementById("distance").innerHTML);
    var cout;
    var airport1 = document.getElementById("autocomplete-airport-1");
    var airport2 = document.getElementById("autocomplete-airport-2");
    var classe;

    var dateComp = dateRetour.getTime() - dateDepart.getTime();


    if (airport1.value == airport2.value) {
        alert("Les aéroports doivent être différents");
        return false;
    } else {

        if (form.adulte.value == 1 && form.enfant.value > 3) {
            alert("Un adulte ne peut pas voyager seul avec plus de 3 enfants");
            return false;
        } else {
            if (dateRetour.getTime() < dateDepart.getTime() || dateDepart.getTime() < date.getTime()-60*60*24*1000) {
                alert("La date de retour ne peut pas être égale ou inférieure à la date de départ qui ne peut être inférieure à la date du jour");
                return false;
            } else {
                if (dateComp < 60 * 60 * 24 * 7 * 1000) {
                    if (distance < 3000) {
                        cout = form.adulte.value * 249 + form.enfant.value * 188;
                    } else {
                        cout = form.adulte.value * 350 + form.enfant.value * 270;
                    }
                } else {
                    if (distance < 3000) {
                        cout = form.adulte.value * 550 + form.enfant.value * 470;
                    } else {
                        cout = form.adulte.value * 680 + form.enfant.value * 600;
                    }
                }
                if (form.eco.checked) {
                    cout = cout;
                    classe = "classe éconimique";
                } else if (form.affaire.checked) {
                    cout = cout * 1.3;
                    classe = "classe affaire";
                } else {
                    cout = cout * 1.7;
                    classe = "première classe";
                }


                var recap = "\nUn vol aller-retour de " + airport1.value + " à " + airport2.value + " pour " + form.adulte.value + " adulte(s) et " + form.enfant.value + " enfant(s) en " + classe + "\nDu " + document.getElementById("depart").value + " au " + document.getElementById("retour").value + " \nPour un total de " + cout + " euros \n \nBon voyage !"
                var recapHTML = "Voici un récapitulatif de votre commande : <br>Un vol aller-retour de " + airport1.value + " à " + airport2.value + " pour " + form.adulte.value + " adulte(s) et " + form.enfant.value + " enfant(s) <br>Du " + document.getElementById("depart").value + " au " + document.getElementById("retour").value + " <br>Pour un total de " + cout + " euros <br> <br>Bon voyage !"
                alert("Voici un récapitulatif de votre commande : " + recap);
                document.getElementById("recap").innerHTML = "Voici un récapitulatif de votre commande : " + recap;
                localStorage.setItem("recapStore", recap);
                localStorage.setItem("prix", cout);
            }
        }

    }
}
              
            
!
999px

Console