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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:12:58+00:00 2026-06-13T12:12:58+00:00

I have a php-site with a form on which i output preselected values via

  • 0

I have a php-site with a form on which i output preselected values via php. On form submit I want to check which values have changed and just submit these via javascript.

These are the preselected values I passed over from php. It’s important that I keep the associative array structure.

var pbData = jQuery.parseJSON("{
"GameMode":"DEATHMATCH",
"Current Map":"VEGAS JUNKYARD",
"Current Missions":["VEGAS JUNKYARD","VILLA","PRESIDIO","KILL HOUSE","MURDERTOWN","CQB TRAINING","STREETS","THREE KINGDOMS CASINO","IMPORT\/EXPORT;"],
"RoundDuration":"3 minutes"}");

I marked the error in the code.

<script>
function displayVars(){
var form = document.getElementById('settings');
var elems = form.elements;
var txt = "";
for (var index = 0; index < elems.length; index++){
    var selIndex = elems[index].selectedIndex;
    if (typeof selIndex !== "undefined"){
        //the Index Name in the json-object and the name of the form-field are the same 
        var idxName = elems[index].name;
//HERE is the problem. I want to access the subobject via a variablename, so i can iterate through it, but that doesnt work.
        console.log ("pbData default = "+pbData.idxName); //always undefined
        if (elems[index].value !== pbData.idx_name){
            //building a POST-Url
            txt = txt + elems[index].name + "=" + elems[index].options[selIndex].value+"&";
        }
    }
}
console.log (txt);
return false;
}
</script>

I know that I could do this differently, also with jQuery. In my case as I have the preselected values as a php-variable in any case, i think it’s easier like this.
I would really like to know how I can iterate through the subobjects via a variable that contains the object names.

  • 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-13T12:12:59+00:00Added an answer on June 13, 2026 at 12:12 pm

    This is due to how you’e trying to access the property of the (JSON) object. Consider

    var o1 = {idxName: true},
        o2 = {foo : 'bar'},
        idxName = 'foo';
    
    o1.idxName;  // true
    o2.idxName;  // undefined
    o2[idxName]; // 'bar'
    

    You need to access the property via pbData[idxName].


    Additionally, you’re not escaping quotes in your JSON string, and line breaks need to be escaped as follows

    var pbData = jQuery.parseJSON("{\
    \"GameMode\":\"DEATHMATCH\",\
    \"Current Map\":\"VEGAS JUNKYARD\",\
    \"Current Missions\":[\"VEGAS JUNKYARD\",\"VILLA\",\"PRESIDIO\",\"KILL HOUSE\",\"MURDERTOWN\",\"CQB TRAINING\",\"STREETS\",\"THREE KINGDOMS CASINO\",\"IMPORT\/EXPORT;\"],\
    \"RoundDuration\":\"3 minutes\"}");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a form (made through codeigniter) that i want to submit with ajax
i have two tables which form part of my login/register system: these are userlogin
I have a PHP site (with CodeIgniter) that includes a registration form. I have
I'm coding a web site and I have a php fonction called site_nav.php which
Here is the site. I have the submit page, and a form action to
I have a form which I submit and I use .serialize to help me
I have a PHP-based site with bookings/appointments stored in a MySQL database. I want
I have a form which automatically refreshes the page on submit, I have tried
I have a contact form on site which used to work, but since last
Let's say I have a form from a remote area http://example.com/form.php which contains: <form

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.