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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:04:11+00:00 2026-06-16T15:04:11+00:00

I have some code that takes in a string, converts it into an Object

  • 0

I have some code that takes in a string, converts it into an Object and allows me to edit via a form. I have an import Function that allows me to bring in another string onto the same object, and I can target on my web form.

I am trying to use a DropDown control to allow me to select which Property in the Object I want to see in the form.

My problem is that once I set the dropdown to 1 of the 3 options I have and click Import however many times it takes to create the target property it breaks and does not allow me to focus on a different property. Its best that I walk you through my demo.

1. Demo Here: http://jsfiddle.net/vJBQq/1/
2. Set dropdown to “View_3”
3. Click Import Button 3 times and the form will populate
4. At this stage, it has dynamically created 3 Properties ‘View_1’, ‘View_2, and ‘View_3. And you are looking at View_3.
5. Try to use the dropdown to target a say View_1. It does not work.

I have two problems at this stage.
a). The dropdown does not target any of the other properties
b). now that the form has been populated, the Import button does not work anymore either. Both controls Return – ReferenceError: Button is not defined

What am I doing wrong to break this.

My code’:

    var cleanStr = '';
var viewDropDown;

$(document).ready(function() {
    //Import String
    $('#import').click(function() {
        ParseFunction();
    });

});

//--------------------Run Import Parse and Set String------------------------------

//Build Initial Object LIst

function ParseFunction(parameterOne) {

    $(document).on('change', '#selectView', function () {
        ParseFunction();
    });

    newStr = 'View{    Image    { BackgroundImage: Image.gif;        Position: 0, 0;        Width: 320;        Height: 480;    }    Button    { BackgroundImage: Button.gif;        Transition: View2;        Position: 49, 80;        Width: 216;        Height: 71;    }    Button    { BackgroundImage: Button2.gif;        Position: 65, 217;        Width: 188;        Height: 134;    }    Label    { Position: 106, 91;        Width: 96;        Height: 34;        Text: "Button";        FontSize: 32;        Color: 0.12549, 0.298039, 0.364706, 1;    }    Scroll    { Position: 106, 91;        Width: 96;        Height: 34;        Button{     BackgroundImage: Button2.gif;            Position: 65, 217;            Width: 188;            Height: 134;        }        Button{     BackgroundImage: Button2.gif;            Position: 65, 217;            Width: 188;           Height: 134;        }    }}' + ' ';

    str = cleanStr += newStr;
    // Set viewDropDown to current selectView State
    viewDropDown = $('#selectView').val();

    var i = {};
    str = str.replace(/(\w+)\s*\{/g, "$1:{"); // add in colon after each named object
    str = str.replace(/\}(\s*\w)/g, "},$1"); // add comma before each new named object
    str = str.replace(/;/g, ","); // swap out semicolons with commas
    str = str.replace(/,(\s+\})/g, "$1"); // get rid of trailing commas
    str = str.replace(/([\d\.]+(, [\d\.]+)+)/g, "[$1]"); // create number arrays
    str = str.replace(/"/g, ""); // get rid of all double quotes
    str = str.replace(/:\s+([^\[\d\{][^,]+)/g, ':"$1"'); // create strings
    //str = str.replace(/([^:]+):{/g, function(m, p1) { return p1 + "_" + (++i).toString() + ":{"; });
    str = str.replace(/(\S+):{/g, function (m, p1) {
        i[p1] = (i[p1] || 0) + 1;
        return p1 + "_" + i[p1].toString() + ":{";
    });
    //console.log(str);
    var objStr;
    eval("objStr={" + str + "};");
    //End Parse String
    console.log(objStr)


    $('#importCode').remove();
    var $objectList = $('<div id="importCode" />').appendTo($('#code'));

    $.each(objStr[viewDropDown], function (k, v) {
        $('<div/>').append(k).appendTo($objectList).on('click', function () {
            $('#options .wrapper').show();
            $('#options div div').hide();
            var $wrapper = $('#options .wrapper').empty();
            if (typeof v === 'string') {
                $('<div class="item" />').append('<span class="key">' + k + '</span>' + '<input value="' + v + '"/>').appendTo($wrapper);
            } else { //object
                $('<h3 class="formHeading" />').append(k).appendTo($wrapper);
                $.each(v, function (key, val) {
                    $('<div class="item" />').append('<span class="key">' + key + '</span>' + '<input value="' + val + '"/>').appendTo($wrapper);
                });
            }

            $("<button>Save</button>").appendTo($wrapper).on('click', function () {
                if (typeof v === 'string') {
                    v = $(this).closest(".wrapper").find("input").val();
                } else { //object
                    $(this).closest(".wrapper").find(".item").each(function (i, div) {
                        var $div = $(div),
                            key = $div.find(".key").text(),
                            val = $div.find("input").val();
                        v[key] = val;
                    });
                }
            });
        });
        cleanStrPre = JSON.stringify(objStr);
        cleanStr = cleanStrPre.substring(1,cleanStrPre.length-1);
        $('#print').append(cleanStr);

    });

};​
  • 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-06-16T15:04:12+00:00Added an answer on June 16, 2026 at 3:04 pm

    I figured it out. Instead of trying to implement it as a single function, I separated them into a Parse into Object function and a Set form function.

    The solution here http://jsfiddle.net/vJBQq/2/

       var cleanStr = '';
    var viewDropDown;
    var objStr;
    
    $(document).ready(function() {
        //Import String
        $('#import').click(function() {
            ParseFunction();
        });
    
    });
    
    //--------------------Run Import Parse and Set String------------------------------
    
    //Build Initial Object LIst
    
    function ParseFunction(parameterOne) {
    
        $(document).on('change', '#selectView', function () {
            setContent();
        });
    
        newStr = 'View{    Image    { BackgroundImage: Image.gif;        Position: 0, 0;        Width: 320;        Height: 480;    }    Button    { BackgroundImage: Button.gif;        Transition: View2;        Position: 49, 80;        Width: 216;        Height: 71;    }    Button    { BackgroundImage: Button2.gif;        Position: 65, 217;        Width: 188;        Height: 134;    }    Label    { Position: 106, 91;        Width: 96;        Height: 34;        Text: "Button";        FontSize: 32;        Color: 0.12549, 0.298039, 0.364706, 1;    }    Scroll    { Position: 106, 91;        Width: 96;        Height: 34;        Button{     BackgroundImage: Button2.gif;            Position: 65, 217;            Width: 188;            Height: 134;        }        Button{     BackgroundImage: Button2.gif;            Position: 65, 217;            Width: 188;           Height: 134;        }    }}' + ' ';
    
        str = cleanStr += newStr;
        // Set viewDropDown to current selectView State
        //viewDropDown = $('#selectView').val();
    
        var i = {};
        str = str.replace(/(\w+)\s*\{/g, "$1:{"); // add in colon after each named object
        str = str.replace(/\}(\s*\w)/g, "},$1"); // add comma before each new named object
        str = str.replace(/;/g, ","); // swap out semicolons with commas
        str = str.replace(/,(\s+\})/g, "$1"); // get rid of trailing commas
        str = str.replace(/([\d\.]+(, [\d\.]+)+)/g, "[$1]"); // create number arrays
        str = str.replace(/"/g, ""); // get rid of all double quotes
        str = str.replace(/:\s+([^\[\d\{][^,]+)/g, ':"$1"'); // create strings
        //str = str.replace(/([^:]+):{/g, function(m, p1) { return p1 + "_" + (++i).toString() + ":{"; });
        str = str.replace(/(\S+):{/g, function (m, p1) {
            i[p1] = (i[p1] || 0) + 1;
            return p1 + "_" + i[p1].toString() + ":{";
        });
        //console.log(str);
        objStr;
        eval("objStr={" + str + "};");
        //End Parse String
        console.log(objStr)
    
    
    };
    
    function setContent() {
        viewDropDown = $('#selectView').val();
        $('#importCode').remove();
        var $objectList = $('<div id="importCode" />').appendTo($('#code'));
    
        $.each(objStr[viewDropDown], function (k, v) {
            $('<div/>').append(k).appendTo($objectList).on('click', function () {
                $('#options .wrapper').show();
                $('#options div div').hide();
                var $wrapper = $('#options .wrapper').empty();
                if (typeof v === 'string') {
                    $('<div class="item" />').append('<span class="key">' + k + '</span>' + '<input value="' + v + '"/>').appendTo($wrapper);
                } else { //object
                    $('<h3 class="formHeading" />').append(k).appendTo($wrapper);
                    $.each(v, function (key, val) {
                        $('<div class="item" />').append('<span class="key">' + key + '</span>' + '<input value="' + val + '"/>').appendTo($wrapper);
                    });
                }
    
                $("<button>Save</button>").appendTo($wrapper).on('click', function () {
                    if (typeof v === 'string') {
                        v = $(this).closest(".wrapper").find("input").val();
                    } else { //object
                        $(this).closest(".wrapper").find(".item").each(function (i, div) {
                            var $div = $(div),
                                key = $div.find(".key").text(),
                                val = $div.find("input").val();
                            v[key] = val;
                        });
                    }
                });
            });
    
    
        });
        cleanStrPre = JSON.stringify(objStr);
        cleanStr = cleanStrPre.substring(1,cleanStrPre.length-1);
        $('#print').append(cleanStr);
    };​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that takes a chart in excel and pastes it into
I have the following piece of code that takes in some words, stores them
I have a function called CreateCriteriaExpression that takes a json string and creates a
I have code that takes an image saved on my computer and processes into
Does anyone have some code that will take a TimeZoneInfo field from .NET and
I have some code that will change the background color of a specific label
I have some code that is supposed to return an NSString. Instead it is
I have some code that generates Visio masters for me, and some masters have
I have some code that causes the box2d physics simulation to stutter forever after
I have some code that runs a model in a loop. Each iteration of

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.