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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:46:17+00:00 2026-05-30T18:46:17+00:00

A simple problem that I just can’t find the ‘right’ answer too. I have

  • 0

A simple problem that I just can’t find the ‘right’ answer too.

I have a PHP script that reads people’s names from a database, and display them in a table. In each row, I have hyperlinked the person’s name to a JavaScript function that displays a popup with the person’s name as the title – the PHP code and resulting html follows:

$name = $results['name'];
echo '<a href="javascript:void(0)" onclick="popup(this, '\' . $name . '\')">' . $name . '</a>';

With html:

<a href="javascript:void(0)" onclick="popup(this, 'Steve Smith')">Steve Smith</a>

Everything works fine, except when I hit a name that has a hyphen, such as “Bryce D’Arnoud” which results in the apostrophe breaking the html. To get around this issue, I am using the PHP addslashes() function, resulting in the following code & html:

$name = $results['name'];
echo '<a href="javascript:void(0)" onclick="popup(this, '\' . addslashes($name) . '\')">' . $name . '</a>';

With html:

<a href="javascript:void(0)" onclick="popup(this, 'Bryce D\'Arnoud')">Bryce D'Arnoud</a>

Everything functions fine, but for some reason, the JavaScript is not removing the escape character, and in the popup() function, if I alert out name, I see “Bryce D\’Arnoud”

function popup(t, name) {
  alert(name);
}

Any suggestions as to where I am going wrong?

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

    First, life would be a lot easier if you didn’t mix JavaScript in your markup. Instead, have PHP form semantic markup, and access the data with JavaScript:

    $name = $results['name'];
    echo '<a href="#" class="popup" data-name="' . $name . '">' . $name . '</a>';
    

    And then access the value (am using jQuery for this for terseness):

    $('.popup').click(function(e) {
        e.preventDefault();
    
        alert($(this).attr('data-name'));
    });
    

    And in native JS (I think):

    document.getElementsByClassName('popup').onclick = function (e) {
        e = e || window.event;
    
        e.preventDefault();
    
        alert(this.getAttribute('data-name'));
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

actually I'm have a very simple problem (that's for sure) I just can't find
I have an extremely odd problem in my JUnit tests that I just can't
I very new to programming and I have a simple problem that I just
I have a very simple problem, but I just can't figure it out. My
This should be a simple problem, but I just can't seem to find a
I have a strange problem that probably has a simple solution that I just
I have simple LINQ problem that I can't figure out. I have a table
Simple problem that I can't figure out... How can I print a '%' character
I have a simple problem that i cannot solve. I have a dictionary: aa
I have a very simple problem and a solution that will work, but I'm

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.