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 6790817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:46:15+00:00 2026-05-26T17:46:15+00:00

I am building a dynamic form creator that allows users to add form elements

  • 0

I am building a dynamic form creator that allows users to add form elements and change the properties. I need to find a way to store this data on the client side without the complexity of XML or JSON. The user could add 50 form elements from text box to radio to textarea. Each element has a different number of changeable variables.

I am currently storing them in hidden fields values like:

type:text, size:30, required:yes, top:30, left:30

type:textarea, cols:30, rows:5, top:50, left:60

I am using jquery to add each item and the hidden.

var typeVariable = 'type:input';

var startPosLeft =  'left:' + Math.round($(newElem).offset().left$('.container').offset().left); 

var startPosTop =  'top:' + Math.round($(newElem).offset().top - $('.container').offset().top); 

var newElemValue = typeVariable + ',' + startPosTop + ',' + startPosLeft;

// creates hidden form elements to store data
$('<input>').attr({'type': 'text', value:newElemValue, 'name':'hidden' + newNumDivs,  id:'hID' + newNumDivs}).appendTo('.hiddenDiv');
  1. Is this the best way to store and retrieve data without doing a ton of ajax calls

  2. How can I call a specific element from a string like:

    type:text, size:30, required:yes, top:30, left:30

I will need ‘text’ not ‘type:text’ .

How can I update a specific element in this string? If size:30 changes to size:50 how do I change this data stored in a hidden field and insert it into

type:text, size:50, required:yes, top:30, left:30
  • 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-26T17:46:16+00:00Added an answer on May 26, 2026 at 5:46 pm

    You should be storing all of that information in a JavaScript array, where each element in the array is an object with the appropriate properties to represent one of the form elements your user is creating. You can easily add elements and update properties of existing items.

    // create empty array
    var formElements = [];
    
    // add a new element to the array
    formElements.push( {
       type : "text",
       size : 50,
       required : "yes",
       top : 30,
       left : 30  
    } );
    
    // individual items in the array can have different properties,
    // e.g., where the one above had "size" this one has "cols":
    formElements.push( {
       type : "textarea",
       cols : 30,
       rows : 5,
       top : 50,
       left : 60       
    } );
    
    // later access the rows property of the 2rd element:
    var rows2nd = formElements[1].rows;
    
    // later change the size property of the 1st element:
    formElements[0].size = 50;
    
    // loop through the array and log the type of each element:
    for (var i=0; i < formElements.length; i++) {
       console.log(formElements[i].type);
    }
    

    When your user is ready to submit you can serialise the array to JSON and submit in a conventional form field or via Ajax.

    UPDATE prompted by your latest comment. To “name the array elements” you use an object instead of an array:

    var formElements = {};
    
    formElements["textTemplate"] = {
       type : "text",
       size : 50,
       required : "yes",
       top : 30,
       left : 30  
    }
    formElements["textareaTemplate"] = {
       type : "textarea",
       cols : 30,
       rows : 5,
       top : 50,
       left : 60  
    };
    

    Or you can define them all in a single statement (note the nested curly braces):

    var formElements = {
            "textTemplate" :    {
                                   type : "text",
                                   size : 50,
                                   required : "yes",
                                   top : 30,
                                   left : 30  
                                 },    
            "textareaTemplate" : {
                                   type : "textarea",
                                   cols : 30,
                                   rows : 5,
                                   top : 50,
                                   left : 60
                                 }
    };
    

    Then to get, say, the “top” property for a “textareaTemplate” you say:

    formElements["textareaTemplate"]["top"];`
    // or in dot notation
    formElements.textareaTemplate.top;
    

    To loop through all items in the object say:

    var currentItem;
    for (var key in formElements) {
       currentItem = formElements[key];
       alert(currentItem["top"]);
    }
    

    For more information see https://developer.mozilla.org/en/JavaScript/Guide/Working_with_Objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently building a dynamic form that allows the user to add as
I am building a dynamic form in that the user can keep adding entries
I'm building an employment application form that's dynamic. I want a field that asks
I am building a dynamic form in a Cocoa application and am planning to
I'm building a dynamic ExtJS form based on JSON data loaded from an ASP.NET
I am considering building an application that is a blend of a dynamic language
I'm building a WinForm with quite a few dynamic elements, and I think I'm
Or possibly there is a better way. I am building a dynamic query builder
I am building a dynamic form builder.. And i have a problem which i
I am building a dynamic (food) menu system for a website. Users will be

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.