Skip to content

Instantly share code, notes, and snippets.

@arvindkalra
Created March 7, 2019 11:55
Show Gist options
  • Save arvindkalra/1e5f87e493d9b989744de2977ecb2b8a to your computer and use it in GitHub Desktop.
Save arvindkalra/1e5f87e493d9b989744de2977ecb2b8a to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact Form</title>
</head>
<body>
<script>
let $body = document.getElementsByTagName('body')[0];
let $form = document.createElement('form');
$body.appendChild($form);
let $name = document.createElement('input');
$name.setAttribute('type', 'text');
$name.setAttribute('placeholder', 'Your Name');
$form.appendChild($name);
let $email = document.createElement('input');
$email.setAttribute('type', 'email');
$email.setAttribute('placeholder', 'Your Email');
$form.appendChild($email);
let $message = document.createElement('input');
$message.setAttribute('type', 'text');
$message.setAttribute('placeholder', 'Your Message');
$form.appendChild($message);
let $button = document.createElement('button');
$button.innerHTML = "Submit";
$form.appendChild($button);
$button.onclick = function (ev) {
ev.preventDefault();
let obj = {};
obj.name = $name.value;
obj.email = $email.value;
obj.message = $message.value;
sessionStorage.setItem('formInput', JSON.stringify(obj));
localStorage.setItem('formInput', JSON.stringify(obj));
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment