convertDistance input cleaner

This commit is contained in:
Divlo 2019-08-29 23:35:40 +02:00
parent 1a9efd50e6
commit 43b337238e
3 changed files with 27 additions and 9 deletions

View File

@ -55,6 +55,10 @@ header {
.container { .container {
padding-bottom: 25px; padding-bottom: 25px;
} }
#firstValue {
width: 25% !important;
display: inline;
}
.table { .table {
color: white; color: white;
} }

View File

@ -97,19 +97,17 @@ $(function () {
$("#submitConvertDistance").click(function() $("#submitConvertDistance").click(function()
{ {
let firstValueEntered = $('#firstValue').val(); let firstValue = $('#firstValue').val();
let secondValueEntered = $("#secondValue option:selected").text(); let unitFirstValue = $("#firstValueUnit option:selected").text();
let secondValue = $("#secondValue option:selected").text();
if(isEmptyValue(firstValueEntered) || isEmptyValue(secondValueEntered)) if(isEmptyValue(firstValue) || isEmptyValue(secondValue))
{ {
$('.results').html(emptyMessageError); $('.results').html(emptyMessageError);
} }
else else
{ {
let firstValue = parseFloat(firstValueEntered.slice(0, firstValueEntered.length - 2));; let result = convertDistance(parseFloat(firstValue), unitFirstValue, secondValue);
let unitFirstValue = firstValueEntered.slice(firstValueEntered.length - 2);
let result = convertDistance(firstValue, unitFirstValue, secondValueEntered);
if(result === messageError) if(result === messageError)
{ {
$('.results').html(messageError); $('.results').html(messageError);

View File

@ -10,9 +10,25 @@
<p class="pt-3 text-center"><?php echo $description?></p> <p class="pt-3 text-center"><?php echo $description?></p>
<br> <br>
<div class="form-group"> <div class="form-group">
<label for="firstValue">Entrez la distance que vous voulez convertir :</label> <label for="firstValue">Entrez la distance que vous voulez convertir et sélectionner l'unité de celle-çi :</label>
<input name="firstValue" type="text" id="firstValue" placeholder="(e.g : 50cm)" class="form-control">
<br> <br>
<input name="firstValue" type="text" id="firstValue" placeholder="(e.g : 50)" class="form-control">
<select id="firstValueUnit">
<option value="pm">pm</option>
<option value="nm">nm</option>
<option value="µm">µm</option>
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="dm">dm</option>
<option value="m">m</option>
<option value="dam">dam</option>
<option value="hm">hm</option>
<option value="km">km</option>
<option value="Mm">Mm</option>
<option value="Gm">Gm</option>
<option value="Tm">Tm</option>
</select>
<br> <br>
<label for="secondValue">Choisissez l'unité que vous voulez avoir après conversion :</label> <br> <label for="secondValue">Choisissez l'unité que vous voulez avoir après conversion :</label> <br>
<select id="secondValue"> <select id="secondValue">
<option value="pm">pm</option> <option value="pm">pm</option>