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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:49:17+00:00 2026-05-22T21:49:17+00:00

i want to display 700 products data in a select box and on per

  • 0

i want to display 700 products data in a select box and on per selection i have to print a table of description . before i was doing ajax call and showing the data but the process is slow. So i have to send all the data to the client side and then use javascript to change the table of description on option change. Below is my code

   <?php
     $data = json_encode( get_data_from_db() );
    ?>

<input type='hidden' name='data' id='data' value= " <?php echo $data; ?>" />

when i do alert in jquery

 alert( $("#data").val() );

i only see

{[

value in the alert but when i print the data on the browser it does print in json format ok.

how can i get this data in the javascript and then i have to use loops to extract the data against a specific id and make ul li out of that and then embedd it. please suggest the right approach and whats wrong with the alert. thanks

  • 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-22T21:49:18+00:00Added an answer on May 22, 2026 at 9:49 pm

    Another solution – instead of creating global variable, set that data as an data- attribute of some related element. Don’t forget to perform json_encode() on whole array/object and then htmlspecialchars() on resulting string (as others have noted, lack of htmlspecialchars() is the reason why you got only “{[” when alerting value of input field). Don’t forget to specify ENT_QUOTES, when calling htmlspecialchars(), or you might have invalid results if any value contains apostrophe character.

    <?php
        $users = array(
            array('name' => 'Average', 'surname' => 'Joe'),
            array('name' => 'Average', 'surname' => 'Jane'),
            array('name' => 'Joe', 'surname' => 'Sixpack'),
            array('name' => 'John', 'surname' => 'Doe'),
            array('name' => 'Hong', 'surname' => 'Gildong'),
            array('name' => 'Foo', 'surname' => 'Bar'),
        );
    ?>
    <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
    <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
    <head>
        <title>sandbox</title>
        <meta http-equiv='content-type' content='text/html; charset=UTF-8'/>
        <script type='text/javascript' src='js/jquery-1.6.1.min.js'></script>
    </head>
    <body data-users='<?php echo htmlspecialchars(json_encode($users), ENT_QUOTES); ?>'>
        <script type='text/javascript'>
            $(function() {
                var users = $(document.body).data('users');
                for ( var n in users ) {
                    $('<div/>').text(users[n].name + ' ' + users[n].surname).appendTo(document.body);
                }
            });
        </script>
    </body>
    </html>
    

    This makes 6 <div/> elements with all names and surnames as their contents.

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

Sidebar

Related Questions

I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in
I have a scenario where I want to display a bunch of data on
I want display data of table. And I can't display instead of the fields-id
I want to display data on table view cell from the database so I
I want display data from database in Listbox...Here is my code, It is not
I have a simple quiz application and I want display a nice timer /
I have this XML i want display all fields on the uiview which comes
I have created a HeaderTemplate for my accordions where I want to display a
I have a UIPickerView with 2 components. I want a UILabel to display the
I want to display the TIME field from my mysql table on my website,

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.