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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:24:18+00:00 2026-06-04T10:24:18+00:00

I have a php page on which I show a jQuery alert when a

  • 0

I have a php page on which I show a jQuery alert when a user adds products to their cart. The message displayed in the alert is a variable from a php page where all language elements are stored.

$cartaddeditem='The product was added to your cart.\r\n You can view your <a href=\'cart.php?action=show\'>shopping cart</a> or click OK to continue shopping';

Then, on the page:

<body onload="jAlert('success', '<?=$cartaddeditem?>', '<?=$minicart?>');" <? } >

The problem is that the alert fails to fire because of the quotes in the $cartaddeditem var and I’m getting an error in firebug that says:

Error: missing ) after argument list
Line: 1, Column: 22
Source Code:
jAlert('success', The product was added to your cart.\r\n You can view your <a href=\

How do I escape the quote in the message string for jQuery? I tried several escaping types with double and single quotes, one or two backslashes but nothing worked.

  • 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-04T10:24:19+00:00Added an answer on June 4, 2026 at 10:24 am

    Try using double quotes to quote your HTML attributes.

    $cartaddeditem = 'The product was added to your cart.\r\n You can view your <a href="cart.php?action=show">shopping cart</a> or click OK to continue shopping';
    

    May I also suggest not adding onload attributes and using $(document).ready( instead?

    $(function(){
        jAlert('success', '<?=$cartaddeditem?>', '<?=$minicart?>');
    });
    

    UPDATE:
    You can also use json_encode to make sure that quotes don’t clash. json_encode works on strings too, it outputs a a string surrounded by double quotes (so don’t add quotes around the parameter).

    $(function(){
        jAlert('success', <?=json_encode($cartaddeditem)?>, <?=json_encode($minicart)?>);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web page which uses in PHP and a jQuery DataTable to
I have a PHP page which breaks down in IE 6 and 7, hence
I have the following in a .htaccess file redirect 301 /page.php http://domain.com/page Which works
We have an existing PHP page (from an earlier project) which could be described
I have an iframe tab which holds php page with various links inside (like
I have an PHP/HTML main page, in which I include different other PHP files
I have a dynamic drop down box which calls another PHP page. I've got
I have web page in PHP which displays all records in a table. I
I have a page (main.php) which loads content from an external PHP file (rpc.php).
I'm pretty new to PHP and have a String which contains an HTML page.

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.