Skip to content

Instantly share code, notes, and snippets.

@lsmith
Created September 17, 2009 23:43
Show Gist options
  • Select an option

  • Save lsmith/188787 to your computer and use it in GitHub Desktop.

Select an option

Save lsmith/188787 to your computer and use it in GitHub Desktop.
<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