$('.button').on('click', function () { var name = prompt('Your Name?', 'Enter your name') if (name != null && name != '') { alert('Your name is ' + name) } else { alert('You did not enter your name!') } })