Jump to content

JS Array - Using PHP to Populate JS Array


Rottingham

Recommended Posts

Hello All,

 

(You can view the page and View Source at http://churchorg.macaction.org - Please log in as guest/guest, navigate to the Service Tab and click Add Service at the bottom of the page.)

 

This is a LITTLE off topic, since it is mostly to do with JS. However, I'm developing a major PHP application and as smart as you folks are, I know I'm in the right place.

 

My problem is this:

 

I have a page where two select boxes containing lists of people ( Left is Absent and Right is Present) driven by several arrays, such as absent_Member, absent_Visitor, and present_Member, present_Visitor.

 

This is so that an additional select box can be used to choose which category you want the select box to display. You can click on people on either side and click a button to swap them across. That is the easy part.

 

The part I am stumped on is my familiarity with JS arrays. I am used to the ease of PHP for searching for values within arrays, such as in_array(needle, haystack);

 

When I swap from on box to another, the only values being passed are options.value ( this equals the persons database ID # ) and options.text ( this equals the persons Last, First name ).

 

The best way I can think to search the arrays to find which one this person resides in is a pathetically taxing way, such as

 

// Remove this person from the absent_ array and add to present_ array
var name = unAttendents[i].text;
var id = unAttendents[i].value;

// Loop through each array until we find this person
for(var i=0; i < absent_Members.length; i++)
{
             if(id == absent_Members[i][0])
// Person Found
}

 

However, I need to keep those arrays updated so that when the select is changed to view a different category of people, it removes the ones take out and displays the proper ones.

 

But I would have to do that for all 6 arrays, and that is within a loop already. Is there any quick way to find array elements, especalially on multidemsional arrays?

 

Thanks for any advice. I know this is a little long-winded and complicated. If you want to Messenger with me, add me as [email protected].

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/45167-js-array-using-php-to-populate-js-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.