Skip to content

Instantly share code, notes, and snippets.

@postpostmodern
Created December 12, 2008 23:37
Show Gist options
  • Save postpostmodern/35340 to your computer and use it in GitHub Desktop.
Save postpostmodern/35340 to your computer and use it in GitHub Desktop.
unform is a function for replacing form controls with plain text using jQuery
// Replaces form controls with plain text
function unform(form_class)
{
$('form.'+form_class+' input[type=text]').each(
function() {
$(this).after('<span class="proxy">' + $(this).attr('value') + '</span>');
$(this).hide();
}
).next().click(
function() {
$(this).prev().show();
$(this).hide();
$('form.' + form_class + ' .submit').show();
}
);
$('form.'+form_class+' textarea').each(
function() {
$(this).after('<span class="proxy">' + $(this).html() + '</span>');
$(this).hide();
}
).next().click(
function() {
$(this).prev().show();
$(this).hide();
$('form.' + form_class + ' .submit').show();
}
);
$('form.'+form_class+' select').each(
function() {
var the_value = $(this).attr('value');
$(this).after('<span class="proxy">' + $(this).find('option[value=' + the_value + ']').html() + '</span>');
$(this).hide();
}
).next().click(
function() {
$(this).prev().show();
$(this).hide();
$('form.' + form_class + ' .submit').show();
}
);
$('form.' + form_class + ' .submit').hide();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment