Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6346907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:06:30+00:00 2026-05-24T21:06:30+00:00

I generate a form with the following html dynamically using jquery: <div id=form_container> <h1><a>Untitled

  • 0

I generate a form with the following html dynamically using jquery:

<div id="form_container">
        <h1><a>Untitled Form</a></h1>
        <form action="save_form" method="post" id="newform" name="newform">
          <div class="form_description">
            <h2 class="editable">Form title. Click here to edit</h2>
            <p class="editable">This is your form description. Click here to edit.</p>
          </div>
          <ul id="form_body" class="ui-sortable">
          <li id="field1" class="world">
            <a href="#" onclick="return false;" class="hover">
            <label class="editable" for="field1">Text1</label>
            <input type="text" name="field1" value="">
            </a>
        </li>
        <li id="field2" class="world">
            <a href="#" onclick="return false;" class="hover">
            <label class="editable" for="field2">Paragraph2</label>
            <textarea cols="" rows="" class="textarea" name="field2"></textarea>
            </a>
        </li>
        <li id="field3" class="world">
            <a href="#" onclick="return false;" class="hover">
            <label class="editable" for="field3">Label3</label>
            <span id="field3">
            <input type="radio" id="field31" name="radiogroup" value="1" class="element radio">
            <label class="choice editable">option1</label>
            <input type="radio" id="field32" name="radiogroup" value="2" class="element radio">
            <label class="choice editable">option2</label>
            <input type="radio" id="field33" name="radiogroup" value="3" class="element radio">
            <label class="choice editable">option3</label>
            </span>
            </a>
        </li>
        </ul>
        </form>

I would like to serialize metadata about the form to database and recreate it later.

- form title
- form description

Fields:
  - field name
  - field type
  - field_text
  - css class (if possible)

I have tried $(‘#newform’).serialize() but it seems to be useful for just getting the name/value pairs of the fields like field1=&field2= and no information about the type of the field.

How do you get no form fields like the header, label etc?

Do I have to get the DOM node for #form_container and look for certain hardcoded values?
Is there a better way to do it?

I am using jquery and rails (2.3.5)

thanks for your help.

Update

Based on Joey’s answer, I came up with the following code that works for me:

$('#newform').find('input').each(function () {
    fields.push({
        name: $(this).attr('name'),
        type: $(this).attr('type'),
        text: $(this).val(),
        class: $(this).attr('class')
    });
    var label = $("label[for='" +  $(this).attr('name') + "']");
    if(label.length != 0) {
        fields.push({
            name: "label",
            type: 'label',
            text: label.text(),
            class: label.attr('class')
        });
    }
});

var form = {
    title: $('.form_description h2').text(), // or whatever the title is
    description: $('.form_description p').text(),
    fields: fields
};

console.log(JSON.stringify(form));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:06:31+00:00Added an answer on May 24, 2026 at 9:06 pm

    You will have to make the object yourself:

    var fields = [];
    $('#myFormTitle').find('inputs').each(function () {
      fields.push({name: $(this).attr('name'), type: $(this).attr('type'), text: $(this).val(), class: $(this).attr('class'), });
    });
    
    var form = {
      title: $('#myFormTitle').text(), // or whatever the title is
      description: 'This is a form',
      fields: fields
    };
    

    Then you could store it (this is just one option of many):

    window.locationStorage.setItem('form', JSON.stringify(form));
    

    and

    var form = JSON.parse(window.localStorage.getItem('form'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following html form, which is generated dynamically: <ul class=precursorList> <li> Precursor
I am using Razor to generate a form. I want to create HTML elements
I have the following aspx/html page, it uses jquery to display a modal form.
I am developing a HTML form designer that needs to generate static HTML and
I'm trying to generate a form using the form_for helper in RoR but I
So I am using the form helper to generate my forms. Up until now
Using CakePHP's form helper to generate a checkbox is easy enough; to use the
Using the following form in a view <% using (Ajax.BeginForm(PatientSearch, new {}, new AjaxOptions()
Based on: MVC Html.CheckBox and form submit issue Let's consider following example. View: <%
I have an HTML document with the following form: <form> <input type=text id=price> <input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.