Sweetalert2 can I compare value from range input?

456 Views Asked by At

I have a range input from Sweetalert2 that shows multiple values from 50 to 4000, in this case I would like to compare the value that the user enters with one already set in a conditional, so that the code shows an alert to the user with the values ​​it needs. The code only works until the moment it confirms the height selected by the user.

<script>
  Swal.queue([{
  title: 'Hemoglobine/Height Simple Calculator',
  confirmButtonText: 'Next &rarr;',
  showCancelButton: true,
  text: 'what is the estimated height??',
  showLoaderOnConfirm: true,
  input: 'range',
  inputAttributes: {
    min: 50,
    max: 4000,
    step: 50
  },
  inputValue: 50,
  preConfirm: function(value) {
    Swal.insertQueueStep({
      type: 'question',
      title: 'Hemoglobine/Height Simple Calculator',
      confirmButtonText: 'Confirm',
      showCancelButton: true,
      text: 'Your value is ' + value + ' Height_above_sea_level?',
    })
  },
  allowOutsideClick: () => !Swal.isLoading()
}]).then((result) => {
  if (result.value[1] > 1000) {
    Swal.fire({
      type: 'success',
      title: 'Success!',
      text: 'The entered values ​​must be reevaluated, subtract -0.2 gr / dL from the hemoglobin values ​​for the new evaluation'
    })
  } 
  
})

if (result.value[1] > 1500) {
    Swal.fire('The entered values ​​must be reevaluated, subtract -0.5 gr / dL from the hemoglobin values ​​for the new evaluation') 
   }
1

There are 1 best solutions below

0
On

did you try to change the array to 0?

if (result.value[0] > 1000)