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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:51:12+00:00 2026-06-01T06:51:12+00:00

I have this array, that I want to parse into javascript. $offerText[] = (

  • 0

I have this array, that I want to parse into javascript.

$offerText[] =

(
[0] => Name
[1] => Adres
[2] => ZIP
[3] => CITY
[4] => E-mail
)

I am using this code to do so:

$html .= '<td class="offerteCell"><a href="#" onclick="return addToOffer('.json_encode($offerText).');" class="offerte">Offerte</a></td>';

In my javascript function i want this array to be posted in an ajax call.

function addToOffer(offer_text) {
    $.ajax({
        url: "offer.php?action=add&offer_text="+offer_text,
        cache: false,
        method: "GET",
        async: false,
        complete: function(request) {
            if(!request || request.readyState != 4 || request.status != 200) return false;
            eval("var obj = "+request.responseText);

            $("span.error").hide();
            $("p").removeClass('error');
            if (obj.errors) {
                for (var i in obj.msg) {
                    $("#error_form_"+i).html(obj.msg[i]).css('display','block');
                    $("#p_form_"+i).addClass('error');

                    alert("error");
                }
            } else {
                var offer = $('#OfferContainer');
                offer.show().html(obj.html);

                var txt = Config.langOfferComplete;
                var buttons = {};
                buttons[Config.langOk] = false;
                buttons[Config.langGoToOffer] = true;

                $.prompt(txt,{
                    submit: function(v,m,f){
                        if (v) {
                            window.location = Config.base + '/' + Config.lang +  "/offer.htm";
                        }
                    },
                    buttons: buttons
                });
            }

            return false;
        }
    });

    return false;
}

But this is not working does somebody knows what I am doing wrong? I watch the output of my html i get this:

<a class="offerte" naam","adres","postcode","woonplaats","e-mailadres"]);"="" onclick="return addToOffer([" href="#">Offerte</a>
  • 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-01T06:51:13+00:00Added an answer on June 1, 2026 at 6:51 am

    That should be

    onclick="return addToOffer('.addslashes(json_encode($offerText)).');"
    

    Consider also using sprintf if you have such confusing string literals, it makes things look simpler:

    $html .= sprintf(
       '<td class="offerteCell">'.
       '<a href="#" onclick="return addToOffer(%s);" class="offerte">Offerte</a>'.
       '</td>',
       addslashes(json_encode($offerText)));
    

    I overdid it with the line breaks here, but I wanted the result to be comfortably viewable in this page.

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

Sidebar

Related Questions

I have a string that looks like this /root/test/test2/tesstset-werew-1 And I want to parse
I have a long string that I need to parse into an array of
I have a log file that I want to parse and load into a
I have a large csv that I want to parse and insert into my
I have an XML file that I want to parse into a database in
I have this Array i wrote a function MostFreq that takes an array of
I have a array that looks like this Array ( [provider] => Array (
I have an array that looks like this: Array ( [0] => Array (
I have an Array that looks like this: array( 0 => array( 'key1' =>
I have an array that looks like this Array ( [0] => Array (

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.