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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:26:45+00:00 2026-05-30T19:26:45+00:00

In another question , it was pointed out that using semantic markup can be

  • 0

In another question, it was pointed out that using semantic markup can be a really clean way to pass data to an onclick function, along the lines of the code below.

I have a second question relating to passing JSON and having the receiving function recognize it as such. I have a PHP generated JSON value of [{"authed":"2012-03-04 17:24:24"},{"authed":"2012-03-04 11:44:38"}] that I need to pass to a function. echoing that straight into the <a> tag won’t work, so I am using urlencode() to get:

<a href="javascript:void(0)" data-auth="%5B%7B%22authed%22%3A%222012-03-04+17%3A24%3A24%22%7D%2C%7B%22authed%22%3A%222012-03-04+11%3A44%3A38%22%7D%5D" onclick="popup(this)">click</a>

Unfortunately, when I alert this out from popup(), I via the following code:

function popup(t) {
  var auth = t.getAttribute('data-auth');

  alert(decodeURI(auth));
}

I get

[{"authed"%3A"2012-03-04+17%3A24%3A24"}%2C{"authed"%3A"2012-03-04+11%3A44%3A38%22"}]

which JSON.parse() is unable to handle. Any suggestions on decoding/passing JSON using this pattern?

  • 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-30T19:26:46+00:00Added an answer on May 30, 2026 at 7:26 pm

    You need to use htmlspecialchars() to escape for html–like you should be doing for everything you echo out in html. (You are doing that right? To prevent generating invalid html?) Don’t use urlencode(), which is for encoding parts of a url path or query parameter.

    <?php
    $data = array(array('authed'=>'2012-03-04 17:24:24'), array('authed'=>'2012-03-04 11:44:38'));
    $jsondata = json_encode($data);
    ?>
    <a data-auth="<?php echo htmlspecialchars($jsondata, ENT_COMPAT, 'UTF-8')?>" onclick="popup(this)">click</a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In another question , a user pointed out that the new keyword was dangerous
I just realized that I've been using std::vector::data() out of similarity with std::string, but
While discussing another question I asked, @Aaron Digulla pointed out the following: If you
I have recently posted another question which straight away users pointed me in the
Another question related to this one . I have a List<SortableObjects> that is the
In another question it was recommend that I try resetting a remote tracking branch
This is somewhat related to another question that I've asked that I've pretty much
I saw that a similar question was asked before, but I don't understand another
This is an interview question that I am using as a programming exercise. Input:
quick question really that has me momentarily stumped. This program searches through a a

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.