Created
September 17, 2009 23:43
-
-
Save lsmith/188787 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <form> | |
| <fieldset id="fields"></fieldset> | |
| </form> | |
| <script> | |
| onload = function () { | |
| var fields = document.getElementById('fields'), | |
| frm = fields.parentNode; | |
| function updateCookie(checkbox) { | |
| } | |
| function addInput(value) { | |
| var inputs = document.getElementsByName('a_text'), | |
| add = true, | |
| div, | |
| i; | |
| for (i = inputs.length - 1; i >= 0; --i) { | |
| if (!/\S/.test(inputs[i].value)) { | |
| add = false; | |
| } | |
| } | |
| if (add) { | |
| div = document.createElement('div'); | |
| div.innerHTML = | |
| '<input type="checkbox" name="a" value=""> ' + | |
| '<input type="text" name="a_text" value="' + (value || '') + '">'; | |
| attach(div); | |
| fields.appendChild(div); | |
| } | |
| } | |
| function attach(el) { | |
| var inputs = el.getElementsByTagName('input'), | |
| checkbox = inputs[0], | |
| text = inputs[1], | |
| last; | |
| checkbox.onclick = function () { | |
| updateCookie(checkbox, text); | |
| }; | |
| text.onblur = function () { | |
| updateCookie(checkbox, text); | |
| addInput(); | |
| }; | |
| } | |
| addInput(); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment