1

I may be going about this the hard way, as I modeled my code after an older article: populating triple dropdown list but I have found I don't need to query the database, because all the information is already neatly stored for me in a PHP array used earlier in the script.

I have a PHP array already created ($events):

<?php foreach($events as $event) {                    

Now I have to pass the events array to another file for processing:

<select name="search_month" onChange="getMonth('filter-leaderboard.php?month='+this.value)">

I'm just not sure how to pass it via Javascript.

How do I go about doing that?

Thanks!

3
  • Serialize the php array and pass ot to your javascript function, then deserialize it again when needed Commented Feb 7, 2014 at 2:09
  • What is in $events? What is your foreach doing? Your onchange event should send the selected value of your select to filter-leaderboard.php as $_GET['month'] but I can't tell much more than that from this question. Commented Feb 7, 2014 at 2:10
  • @Okonomiyaki3000 - $events is an already set and functioning array. The foreach is going through each event and running some statements. This is already existing code that is working fine. I was just showing that to say that I do have an existing and functioning array that I could pass and manipulate in my secondary PHP script. I need the month and the extra data in the $events array to create my new options. Commented Feb 7, 2014 at 23:58

1 Answer 1

1

Looking at your question, it appears you're trying to get the month using AJAX?

If so, it'd probably be better to post the array as the body rather than doing a get request.

You can use the json_encode function (https://www.php.net/json_encode) to convert the array into a JSON object so you can work with it in JavaScript.

1
  • Using json_encode was my solution and I was still able to do a get request. However, what do you mean by "post the array as the body"? I'd rather do that if it means better code. Thanks! Commented Feb 8, 2014 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.