<?php
|
/*---------------------------------------------------------------*/
|
/*
|
Titre : Convertisseur dynamique JS mètre, feet, cm, km...
|
|
URL : https://phpsources.net/code_s.php?id=816
|
Auteur : jerusalem
|
Date édition : 11 Jan 2019
|
Date mise à jour : 19 Aout 2019
|
Rapport de la maj:
|
- fonctionnement du code vérifié
|
*/
|
/*---------------------------------------------------------------*/?>
|
<?php echo 'Convertisseur JS'; ?>
|
|
<div>
|
<p >Tapez une valeur dans l'un des champs à Â convertir:</p>
|
<div >
|
<label>Feet</label>
|
<input id="inputFeet" type="number" placeholder="Feet"
|
oninput="lengthConverter(this.id,this.value)" onchange="lengthConverter(this.id
|
,this.value)">
|
</div>
|
<div class="w3-half w3-margin-top">
|
<label>Meters</label>
|
<input id="inputMeters" type="number" placeholder="Meters"
|
oninput="lengthConverter(this.id,this.value)" onchange="lengthConverter(this.id
|
,this.value)">
|
</div>
|
<div class="w3-half w3-margin-top">
|
<label>Inches</label>
|
<input id="inputInches" type="number" placeholder="Inches"
|
oninput="lengthConverter(this.id,this.value)" onchange="lengthConverter(this.id
|
,this.value)">
|
</div>
|
<div class="w3-half w3-margin-top">
|
<label>cm</label>
|
<input id="inputcm" type="number" placeholder="cm"
|
oninput="lengthConverter(this.id,this.value)" onchange="lengthConverter(this.id
|
,this.value)">
|
</div>
|
<div class="w3-half w3-margin-top">
|
<label>Yards</label>
|
<input id="inputYards" type="number" placeholder="Yards"
|
oninput="lengthConverter(this.id,this.value)" onchange="lengthConverter(this.id
|
,this.value)">
|
</div>
|
<div class="w3-half w3-margin-top">
|
<label>Kilometers</label>
|
<input id="inputKilometers" type="number" placeholder="Kilometers"
|
oninput="lengthConverter(this.id,this.value)" onchange="lengthConverter(this.id
|
,this.value)">
|
</div>
|
<div class="w3-half w3-margin-top">
|
<label>Miles</label>
|
<input id="inputMiles" type="number" placeholder="Miles"
|
oninput="lengthConverter(this.id,this.value)" onchange="lengthConverter(this.id
|
,this.value)">
|
</div>
|
</div>
|
|
<script>
|
function lengthConverter(source,valNum) {
|
valNum = parseFloat(valNum);
|
var inputFeet = document.getElementById("inputFeet");
|
var inputMeters = document.getElementById("inputMeters");
|
var inputInches = document.getElementById("inputInches");
|
var inputcm = document.getElementById("inputcm");
|
var inputYards = document.getElementById("inputYards");
|
var inputKilometers = document.getElementById("inputKilometers");
|
var inputMiles = document.getElementById("inputMiles");
|
if (source=="inputFeet") {
|
inputMeters.value=(valNum/3.2808).toFixed(2);
|
inputInches.value=(valNum*12).toFixed(2);
|
inputcm.value=(valNum/0.032808).toFixed();
|
inputYards.value=(valNum*0.33333).toFixed(2);
|
inputKilometers.value=(valNum/3280.8).toFixed(5);
|
inputMiles.value=(valNum*0.00018939).toFixed(5);
|
}
|
if (source=="inputMeters") {
|
inputFeet.value=(valNum*3.2808).toFixed(2);
|
inputInches.value=(valNum*39.370).toFixed(2);
|
inputcm.value=(valNum/0.01).toFixed();
|
inputYards.value=(valNum*1.0936).toFixed(2);
|
inputKilometers.value=(valNum/1000).toFixed(5);
|
inputMiles.value=(valNum*0.00062137).toFixed(5);
|
}
|
if (source=="inputInches") {
|
inputFeet.value=(valNum*0.083333).toFixed(3);
|
inputMeters.value=(valNum/39.370).toFixed(3);
|
inputcm.value=(valNum/0.39370).toFixed(2);
|
inputYards.value=(valNum*0.027778).toFixed(3);
|
inputKilometers.value=(valNum/39370).toFixed(6);
|
inputMiles.value=(valNum*0.000015783).toFixed(6);
|
}
|
if (source=="inputcm") {
|
inputFeet.value=(valNum*0.032808).toFixed(3);
|
inputMeters.value=(valNum/100).toFixed(3);
|
inputInches.value=(valNum*0.39370).toFixed(2);
|
inputYards.value=(valNum*0.010936).toFixed(3);
|
inputKilometers.value=(valNum/100000).toFixed(6);
|
inputMiles.value=(valNum*0.0000062137).toFixed(6);
|
}
|
if (source=="inputYards") {
|
inputFeet.value=(valNum*3).toFixed();
|
inputMeters.value=(valNum/1.0936).toFixed(2);
|
inputInches.value=(valNum*36).toFixed();
|
inputcm.value=(valNum/0.010936).toFixed();
|
inputKilometers.value=(valNum/1093.6).toFixed(5);
|
inputMiles.value=(valNum*0.00056818).toFixed(5);
|
}
|
if (source=="inputKilometers") {
|
inputFeet.value=(valNum*3280.8).toFixed();
|
inputMeters.value=(valNum*1000).toFixed();
|
inputInches.value=(valNum*39370).toFixed();
|
inputcm.value=(valNum*100000).toFixed();
|
inputYards.value=(valNum*1093.6).toFixed();
|
inputMiles.value=(valNum*0.62137).toFixed(2);
|
}
|
if (source=="inputMiles") {
|
inputFeet.value=(valNum*5280).toFixed();
|
inputMeters.value=(valNum/0.00062137).toFixed();
|
inputInches.value=(valNum*63360).toFixed();
|
inputcm.value=(valNum/0.0000062137).toFixed();
|
inputYards.value=(valNum*1760).toFixed();
|
inputKilometers.value=(valNum/0.62137).toFixed(2);
|
}
|
}
|
</script>
|
|
|
Administrateur
11 Jan 2019 à 11:05Ce n'est pas du php mais il fonctionne nickel ce petit bout de code.