From 43b337238e4607517d6eccf52c58f6753a22d63a Mon Sep 17 00:00:00 2001 From: Divlo Date: Thu, 29 Aug 2019 23:35:40 +0200 Subject: [PATCH] convertDistance input cleaner --- css/style.css | 4 ++++ scripts/main.js | 12 +++++------- views/function-views/convertDistance.php | 20 ++++++++++++++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/css/style.css b/css/style.css index c05db02..9dbd4e6 100644 --- a/css/style.css +++ b/css/style.css @@ -55,6 +55,10 @@ header { .container { padding-bottom: 25px; } +#firstValue { + width: 25% !important; + display: inline; +} .table { color: white; } diff --git a/scripts/main.js b/scripts/main.js index 36a63c4..ddeeddd 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -97,19 +97,17 @@ $(function () { $("#submitConvertDistance").click(function() { - let firstValueEntered = $('#firstValue').val(); - let secondValueEntered = $("#secondValue option:selected").text(); + let firstValue = $('#firstValue').val(); + 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); } else { - let firstValue = parseFloat(firstValueEntered.slice(0, firstValueEntered.length - 2));; - let unitFirstValue = firstValueEntered.slice(firstValueEntered.length - 2); - - let result = convertDistance(firstValue, unitFirstValue, secondValueEntered); + let result = convertDistance(parseFloat(firstValue), unitFirstValue, secondValue); if(result === messageError) { $('.results').html(messageError); diff --git a/views/function-views/convertDistance.php b/views/function-views/convertDistance.php index 6120e16..d455164 100644 --- a/views/function-views/convertDistance.php +++ b/views/function-views/convertDistance.php @@ -10,9 +10,25 @@


- - +
+ + +