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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:40:16+00:00 2026-05-28T01:40:16+00:00

Hello there I have a really complex php script that produces a javascript file

  • 0

Hello there I have a really complex php script that produces a javascript file in jquery
There is a string that is stored in an input type text and I want to converted into json.
The input type text has undedined number of elements.
So I initisialize the string in the input box

<input type="text" id="selectbuttons" value="{}">

After some actions the string in the input box is something like that:

{"button":"bt1","style":"style1"},{"button":"bt2","style":"style2"}

etc…

Then this is my script , i use the function addScriptto to add it to the document’s header, also I am using the core of jquery jquery-1.6.2.min.js to make the json object

$document->addScriptto('
$.noConflict();
jQuery(document).ready(function($) {
var loaded=$("#selectButtons").val();
var obj = jQuery.parseJSON(loaded);
}); //end of dom ready

');

But I can’t make it work, when the string is not empty
Is there something wrong with my json syntax? Also, I would be later able to loop all the elements and retrieve the data? Thanks in advance

  • 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-28T01:40:16+00:00Added an answer on May 28, 2026 at 1:40 am

    Your JSON string should be in an array format like below

    [{"button":"bt1","style":"style1"},{"button":"bt2","style":"style2"}]
    

    And then you can use the $.each to loop through the JOSN values as below:

    $.each(yourJSONstring,function(i,values) {
      //yourJSONstring holds the JSON array
      // i is just the loop index. it will increment by 1 in every loop
      alert(values.button) //will alert bt1 in the 1st loop, bt2 in 2nd
      alert(values.style) //will alert style1 in 1st loop, style2 in 2nd
      //You can have values here of the keys in JSON using the dot notation as above and do your operations.
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have really simple problem in my PHP script. There is a function defined
Oh hello there, fellow SO members, I have a web service that returns XML
Hello All I am using infragsitics tree view control.I have one stored procedure that
Let's say I have these two arrays: string[] arr1 = new string[2]{Hello, Stack} string[]
Hello is there a class that does a pretty conversion?
Hello there I am having some thoughts on my file structure in codeigniter.What I'm
Hello internet, I have been looking for the past two hours for a script
I've got a big project written in PHP and Javascript. The problem is that
Hello to all you people out there I have been trying to download the
I've never really used MS server or anything like that before, i have, however

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.