🤯 $3/m for 3 month Sale Get 700+ Assessments, Books and Courses!

jQuery convert input to text

Sam Deering
Share

Use jQuery to convert your form inputs into text elements. At the moment the script only works for text inputs but could easily be extended to work for other input types such as textarea, radio, checkbox etc…

$form = $('#register-form1');
$form.find(':input').each( function(i,v)
{
    var iElem = $(v),
        name = iElem.attr('name'),
        type = iElem.attr('type'),
        labelElem = iElem.parents().find('label[for="'+name+'"]'),
        labelTxt = labelElem.html(),
        iVal = iElem.val();

    if(type == 'input')
    {
    iElem.parent().prepend('

'+labelTxt+' '+iVal+'

'); } else if (type == 'password') { iVal = iVal.substr(i).replace(/[S]/g, "*"); iElem.parent().prepend('

'+labelTxt+' '+iVal+'

'); } //remove old input elements iElem.remove(); labelElem.remove(); });