Skip to content

Instantly share code, notes, and snippets.

@overthemike
Created July 11, 2017 23:20
Show Gist options
  • Save overthemike/7a6828c09b5e90189ac8348e5de6c670 to your computer and use it in GitHub Desktop.
Save overthemike/7a6828c09b5e90189ac8348e5de6c670 to your computer and use it in GitHub Desktop.
let fields = document.querySelector('#fields')
let htmlStr = '<form>'
formData.forEach(function(item){
if (item.type === 'text' || item.type === 'email' || item.type === 'tel') {
htmlStr += `<input type="${item.type}" placeholder="${item.label}" id="${item.id}" />`
}
if (item.type === 'textarea') {
htmlStr += `<textarea id="${item.id}" placeholder="${item.label}"></textarea>`
}
if (item.type === 'select') {
htmlStr += `<select id="${item.id}">`
htmlStr += `<option value="">${item.label}</option>`
item.options.forEach(function(option){
htmlStr += `<option value="${option.value}">${option.label}</option>`
})
htmlStr += '</select>'
}
})
htmlStr += '</form>'
fields.innerHTML = htmlStr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment