Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                section.section
  div.container
    h1.title Parse form to JS/json object
    form#form(onsubmit="serialize();return false")
      div.field
        label.label Name
        div
          input#name.input.is-primary(name="name", value="ivanaugustobd",  placeholder="Enter your name here", autofocus, required)
      div.field
        label.label Year of birth
        div.control
          span.select.is-primary
            select#yob(name="yob")
              - for (var year = 2017; year > 1950; year--)
                option(value=year)=year
      div.field
        label.label Do you agree?
        div.control
          label.radio
            input(type="radio", name="confirmation", value="1")
            span Yes
          label.radio
            input(type="radio", name="confirmation", value="0", checked)
            span No
      div.field
        label.label Subscribe to newsletter
        label.checkbox
          input(type="checkbox", name="subscribe", checked)
          span Yes, I'm in
      div.field
        label.label Observation
        div.control
          textarea.textarea(name="observation") Lorem ipsum dolor sit amet, consectetur adipisicing elit. Esse nam dolore possimus quisquam libero expedita cupiditate optio modi, ea, doloribus consequatur veritatis et ut. Illo praesentium voluptate, velit itaque repellendus!
      div.field
        div.control
          button.button.is-primary(type="submit") Parse form to object
    br
    div#message.notification.is-info.is-hidden Done! See result in console.

              
            
!

CSS

              
                
              
            
!

JS

              
                class FormToJson {
  constructor (selector) {
    document.querySelector(selector).querySelectorAll('input, select, textarea').forEach(field => {
      this[field.name] = field.value
    })
  }
}

const serialize = () => {
  const formData = new FormToJson('#form') // here goes the parse
  
  document.getElementById('message').classList.remove('is-hidden')
  console.clear()
  console.log('// TODO: review support to radio/checkbox and array[fields]')
  console.log(formData)
}

              
            
!
999px

Console