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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:17:26+00:00 2026-05-31T23:17:26+00:00

I have a main select list of courses which drives various things on a

  • 0

I have a main select list of courses which drives various things on a page. When a course is selected another select list will be repopulated with the start date of that course up to 6 months in advance. Also, I have a table on the page with the students name and phone number, when a course is selected, the table will be repopulated with all the students enrolled onto that course. My problem is I will be getting various different things from PHP via JSON i.e. the students and the starting date. How can I therefore pass more than one thing to jQuery? What if the course select list affected not just 2 things but 3, 5 or even 10? How would we handle that with PHP and jQuery?

foreach($m as $meta)
{
        $metaCourse = $this->getCourseInfo($meta['parent_course']);

        //populate the select list with the name of each course
        $metaSelectList .= '<option id="select'.$count.'" value="'.$metaCourse['id'].'">'.$metaCourse['fullname'].'</option>';
        $count++;

        //get only the first course's dates
        if($count3 == 1)
        {
                $startDate =  intval( $course->getStartDate(50) );
                $endDate =  strtotime('+6 month', $startDate);

                //populates the select list with the starting date of the course up to the next six months
                for($date = $startDate; $date <= $endDate ; $date = strtotime('+1 day', $date))
                {
                        $dateSelectList .= '<option id="select'.$count2.'" value="'.$date.'">'.date('D d F Y', $date).'</option>';
                        $count2++;
                }
                $count3++;
                $students = $s->getStudents($metaCourse['id']);
                $content = $this->createStudentTable($students);

        }
}

This is my handler for the AJAX…FOR NOW (I haven’t implemented the students table yet as I’m still trying to figure out how to pass multiple pieces of data to jQuery). Basically each time a course is selected, PHP creates a new select list with the appropriate dates and then passes it to jQuery. I’m not sure if I should do this in JavaScript or in PHP.

if (isset($_GET['pid']) && (isset($_GET['ajax']) && $_GET['ajax'] == "true"))//this is for lesson select list
{
        $pid = intval( $_GET['pid'] );
        $c = new CourseCreator();
        $startDate =  intval( $c->getStartDate($pid) );
        $endDate =  strtotime('+6 month', $startDate);
        $dateSelectList = '<select name="dateSelect" id="dateSelect">';

        //populates the select list with the starting date of the course up to the next six months
        for($date = $startDate; $date <= $endDate ; $date = strtotime('+1 day', $date))
        {
                $dateSelectList .= '<option id="select'.$count2.'" value="'.$date.'">'.date('D d F Y', $date).'</option>';
                $count2++;
        }

        $dateSelectList .= '</select>';

        echo json_encode($dateSelectList);
        exit;
}

My jQuery handler:

$('#metaSelect').live('change', function()
{
    $.getJSON('?ajax=true&pid='+$('#metaSelect').val(), function(data)
    {           
        alert(data);
        $('#dateSelectDiv').html(data);
    }); 

});  
  • 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-31T23:17:27+00:00Added an answer on May 31, 2026 at 11:17 pm

    You can easily pass ALOT of data from PHP to your HTML via JSON (which you seem to of put in basic already)

    However to expand on what you have – heres a quick example

    <?php
       $arrayOfStuff = array("theKey" => "theEntry", 123 => "Bob Dow", 56 => "Charlie Bronw", 20 => 'Monkey!', "theMyID" => $_POST['myID']);
       echo json_encode($arrayOfStuff);
    ?>
    

    On your HTML side.

    <script> 
       $.post("/theurl/", {type: "fetchArrayOfStuff", myID: 24}, function(success) {
           //your success object will look like this
           /*
              {
                 theKey: 'theEntry',
                 123: 'Bob Dow',
                 56:  'Charlie Bronw',
                 20:  'Monkey!',
                 theMyID: 24
              }
           so you can easily access any of the data.
                      alert(success.theKey);
                      alert(success[123]);
                      alert(success[56]);
                      alert(success[20]);
                      alert(success.theMyID);
    
           */
    
           //we can iterate through the success JSON!           
           for(var x in success) { 
               alert(x + "::" + success[x]);
           };
       }, "json");
    </script>
    

    In the long run – your MUCH better of letting the backend do the backend stuff, and the front end doing the front-end stuff.

    What this means is, try keep the HTML generation as far away as possible from the back-end, so instead of constantly passing

        for($date = $startDate; $date <= $endDate ; $date = strtotime('+1 day', $date))
        {
                $dateSelectList .= '<option id="select'.$count2.'" value="'.$date.'">'.date('D d F Y', $date).'</option>';
                $count2++;
        }
    

    You could perhaps

        $date = $startDate;
        $myJson = array()
        while($date <= $endDate) {
            $myJson[] = array("date" => $date, "formattedDate" => date('D d F Y', $date));
            $date += 86400; //86400 is the value of 1 day.
        }
        echo json_encode($myJson);
    

    And you can just do a simple iteration on your HTML code.

    <script> 
       $.get("/", {ajax: true, pid: $('#metaSelect').val()}, function(success) {
    
    
           //we can iterate through the success JSON!           
           var _dom = $('#dateSelectDiv').html(''); //just to clear it out.
    
           for(var x in success) { 
              _dom.append("<option value='"+success[x].date+"'>"+success[x].formattedDate+"</option>");
           };
       }, "json");
     </script>
    

    So as you can see – you can pass alot of data using JSON

    Maybe look at some of the documentation to – http://api.jquery.com/jQuery.get/ , http://api.jquery.com/jQuery.post/ – might give you more ideas.

    Best of luck to you

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

Sidebar

Related Questions

i have this hap code of which tries to selects sub-node from the main
I have main window which has inner grid components. When I press a button
I have main table called 'Employee' and another slave table called 'EmployeeTypes' that has
i have main activity in which i have Four menus. and i have one
I have this function for adding options to a Select list: function addOption(selectbox, value,
An application I'm developing requires that the app main a local list of things,
I have created one drop down for pasize selection. <s:select name=pageSize cssClass=drop list=#actResultLimitValue.lstEntities listKey=code
I built a classified. In the main/index.php page, I have many categories like cars,
I currently have an Ajax pop up window displayed from the main page of
I have an SQL SELECT statement joining 2 tables. The main table contains misc

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.