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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:44:38+00:00 2026-06-12T12:44:38+00:00

I’m going to do my best explaining this, as I’m fumbling around a bit

  • 0

I’m going to do my best explaining this, as I’m fumbling around a bit as it’s my first time doing anything like this.

At the beginning of my page I call a function that returns 3 recipe’s, I then create variables and assign each with a recipe id:

$meal = builder::buildMealPlan(1200,0,0,0,3);

$id1 = $meal[0][id];
$id2 = $meal[1][id];
$id3 = $meal[2][id];

So I now know the id’s of the 3 recipe’s that have been chosen by the function, I then display these 3 recipe’s in 3 div’s:

<div id="meal1"><h2><? print_r($meal[0]); ?></h2></div>
<div id="meal2"><h2><? print_r($meal[1]); ?></h2></div>
<div id="meal3"><h2><? print_r($meal[2]); ?></h2></div>

When any of these div’s are clicked it means you don’t like that recipe and want a different one, it calls a page with 4 parameters (id1,id2,id3,clicked), basically telling it the 3 recipe’s that are currently displayed as well as which one was clicked, so I can find another combination of recipes with 2 of the same id’s, as well as the new one:

$(document).ready(function(){
$("#meal1").click(function(){
  $.get("testing-01.php?id1=<?echo $id1;?  >&id2=<?echo $id2;?>&id3=<?echo $id3;?>&clicked=1", function(result){
    $("#meal1").html(result);
});

});

This works great, a proper recipe is selected and the div is refreshed with the new recipe, however my problem is now, if you click any of the div’s again, it refreshes with the same recipe over and over again, because my php variables ($id1, $id2, $id3) are always the same value, since the page is never reloaded.

My question: How can I set a javascript variable with the result of my onclick event? Right now the on click event replaces the div with data from:

$.get("testing-01.php?id1=<?echo $id1;?  >&id2=<?echo $id2;?>&id3=<?echo $id3;?>&clicked=1

However I need to somehow update the variables that I’m sending in the above statement with new values each time a div is clicked.

If you’ve read this far, thanks, if I’ve left important/obvious things out please just let me know and I’ll add it in.

EDIT: Ok, I’ve got it outputting JSON now:

  {"mealnumber":1,"id":"69","title":"Protein Packed Meatloaf","description":"This meatloaf is packed with protein to help your muscles grow.","cookingtime":"00:25 ","preptime":"00:10 ","servings":"4.00","rating":"0.000","calories_ps":"205.00","carbohydrate_ps":"7.70","protein_ps":"20.55","fat_ps":"9.64"}

My JS code to try and show that I’m at least reading it correctly:

 $(document).ready(function(){
 $("#meal1").click(function(){

     $.getJSON("testing-01.php?id1="+id1+"&id2="+id2+"&id3="+id3+"&clicked=1",      function(data) {
        $.each(data.items, function(i, item) {
        console.log(item.id);
        alert(item.id);
        });
    });
    });

});

However nothing is logged or alerted when I click the div… am I missing something obvious here? I can see in the console that it’s calling to the correct page, if I copy and paste the URL I get the json code I pasted above.

  • 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-12T12:44:39+00:00Added an answer on June 12, 2026 at 12:44 pm

    Im not sure i understand all you need, but i guess you need to change this 3 ID’s in get method.

    You could make some simple javascript object that store 3 id’s, and rewrite it on success ajax… Buy you need better repsonse then just html… Try json…

     $(document).ready(function(){
        $("#meal1").click(function(){
          $.get("testing-01.php?id1="+SomeJavascriptObject.id1"&id2="+SomeJavascriptObject.id2"&id3="+SomeJavascriptObject.id3"&clicked=1", function(result){
    
           SomeJavascriptObject.id1 =result.returnedID1;
     SomeJavascriptObject.id2 = result.returnedID2;
     SomeJavascriptObject.id3 = result.returnedID3;
            $("#meal1").html(result.html);
        });
    

    Maybe this can help you.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.