1

How can I put up a condition for the string entered in input field like if userName equals to 'xyz' then swal("welcome!") else swal("better next time")? So far I have my code given below.

> swal({
         title: "Proceeding...",
         content: {
                  element: "input",
                  attributes: {
                      placeholder: "Type up your userName",
                      type: "userName",
                  },              
                },
       });
Doraemon
  • 23
  • 5

1 Answers1

0

You could:

swal("Write something here:", {
  content: "input",
})
.then((value) => {
  if (value === 'xyz') {
    swal(`Username: ${value}`);
  }
});

Refer to: https://sweetalert.js.org/guides/#using-dom-nodes-as-content

theonelucas
  • 584
  • 7
  • 12