Get value from SweetAlert2 select box?

Viewed 13017

I have the following code... which is used for a sweet alert text box

swal({
  title: 'Select an Item',
  input: 'select',
  inputOptions: listOfItemsForSelectBox,
  inputPlaceholder: 'Select country',
  showCancelButton: true,
  inputValidator: function (value) {
    return new Promise(function (resolve, reject) {
      if (value != null) {
        resolve()
      }
    })
  }
}).then(function (result) {
  swal({
    type: 'success',
    html: 'You selected: ' + result
  })
})

For some reason, it just returns "true" in the 'You selected' part...

I want to get the item's id.

2 Answers
}).then(function (result) {
  swal({
    type: 'success',
    html: 'You selected: ' + result
  })
})

should be

}).then(function (result) {
  swal({
    type: 'success',
    html: 'You selected: ' + result.value
  })
})

if you output 'result' to a console you will see all the data that is associated with the 'result' variable. (i.e. console.log(result))

Related