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

  • Home
  • SEARCH
  • 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 5938899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:45:01+00:00 2026-05-22T15:45:01+00:00

I was wondering if it’s possible to have a function in a class, that

  • 0

I was wondering if it’s possible to have a function in a class, that you call on the same page, but it needs to echo different stuff from the array.

What I mean:

If this is my array:

| Day | Comment |
|-----|---------|
|  1  |  hallo  |
|-----|---------|
|  2  |  hey    |
|-----|---------|
|  3  |  hello  |
|_____|_________|

And if I click on day 1, the content from the array where day = 1 should appear, if I click day 2, the content of day 2 should appear.

Is it possible to create a function does this and that I can echo on the same page with the same function.
Like:

--------------------------------------------
|   <div id="day1"> content day 1 </div>   |
|   <div id="day1"> content day 2 </div>   |
|   <div id="day1"> content day 3 </div>   |
--------------------------------------------
  • 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-22T15:45:02+00:00Added an answer on May 22, 2026 at 3:45 pm

    Yes, it is possible if you use JQuery but this might looked like an intermediate solution so I will try my best to explain as much as possible. You can refer to the code below and placed them in the same page as your PHP.

    1) Firstly Load Jquery at your header and lets assumed your array variable is named myarray.

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
    

    2) Add the below script section preferably on top of your page.

    <script type="text/javascript">
       $('#day1').click(function(){
          $(this).html(myarray[0]);
       });
    
       $('#day1').click(function(){
          $(this).html(myarray[1]);
       });
    
       $('#day1').click(function(){
          $(this).html(myarray[2]);
       });
    </script>
    

    3) Explanation of the code, Jquery works by locating id or class of any element and performed some action. When a user clicks or perform an action (in your case, I would assumed by clicking the div) Jquery will refer to the script above and see if it matches any div’s id. If a match is found, it will trigger the click function and perform a task.

    4) $(this).html is a function to display html or text between the div’s content, in this case that would be your array’s value. this means the element that the user clicks and varies based on id name.

    Try it out, you will be impressed with what Jquery can do and soon you will be addicted to it. 🙂 Cheers!

    5) A more reusable and dynamic function that will crop out id's name to select the array when more are added.

    In the div html code, please add a class to all the div like below.

    <div class='onClickLoadArray' id='day1'></div>
    
    <script type="text/javascript">
    
       $('.onClickLoadArray').click(function(){
          var tmpArrayCount = ($(this).attr('id').replace('day', ''))-1;
          $(this).html(myarray[tmpArrayCount]);
       });
    
    </script>
    

    I didn’t test this yet but this should work, it will strip the div’s id down to a number then subtract by 1 because array starts with 0. Then load the array’s value into the div’s that clicks it.

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

Sidebar

Related Questions

Just wondering, will it be possible we can check whether the page is call
Wondering if its' possible to have solution within solution in vs 2010? How? thanks
wondering if there's any way to make it so that a list I have
Wondering if someone can answer something that has stumped me. I have a Timer
Wondering how to open many new windows with Javascript. I have found plenty of
Wondering if anyone can help me with this annoying but trivial (in terms of
I have text I am displaying in SIlverlight that is coming from a CMS
Wondering if I'm going about this the right way or not. I have 3
Wondering if there is a way to change the object on the heap that
Wondering if its possible to Moq the Prism EventAggregator Let's take the EventAggregator Quickstart

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.