Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
  </head>
  <body>
    <form>
      <label>Name:</label>
      <input type="input" />
      <button>Submit this form</button>
    </form>
    
    <script src="https://code.jquery.com/jquery-2.0.3.js"></script>
  </body>
</html>
 
$(() => {
 
 // listen for a .submit() event on the <form> element
 $('form').submit((event) => {
   // prevent default behavior of forms
   event.preventDefault()
   
   // read data from text field
   const name = $('input').val()
   
   if (name === '') {
     alert('Please enter a name')
   } else {
     alert(`Hello ${name}!`)
   }
  })
})
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x