UNPKG

form-js

Version:

Create better ui form elements. Supports IE9+, all modern browsers, and mobile.

74 lines (58 loc) 1.56 kB
<html> <body> <style> /* hide the dropdown options container initially */ select { display: none; } .my-dropdown { width: 200px; height: 20px; position: relative; cursor: pointer; } .my-dropdown-options-container { position: absolute; top: 0; left: 0; display: none; background: grey; width: 100%; height: auto; } /* when the dropdown options container is shown */ .my-dropdown-options-container-active .my-dropdown-options-container { display: block; } .dropdown-option { box-sizing: border-box; padding: 6px 0; border-bottom: 1px solid black; } </style> <!-- our starter html --> <h1>The world's simplest form</h1> <form> <input type="checkbox" value="" name="mycheck" /> <input type="text" value="" name="name" /> <select> <option value="a" selected>Apples</option> <option value="b">Bananas</option> <option value="c">Curry Chicken</option> </select> <label><input type="radio" value="girl" name="gender" /> Woman</label> <label><input type="radio" value="boy" name="gender" /> Guy</label> </form> <script src="../dist/form.js"></script> <script> var form = new Form({ el: document.getElementsByTagName('form')[0], onChange: function (value, formElement) { console.log(arguments); } }); // set up the form and prep the DOM form.setup(); </script> </body> </html>