0

My page has a dropdownlist with three options {1,2,3} and three divs {div1, div2,div3}. I am loading and displaying content of my php array in all the three divs based on few conditions.

When i selected dropdown values, i want the corresponding div to be shown and other to be hidden. eg. if i select drop down option 2, div2 should be shown and div1 and div3 should be hidden.

On page load, I hide div2 and div3 and show only div1. Currently i load the content of all three divs on page load (php foreach loops on the array, whose size is huge) and then control the visibility of divs through javascript. This makes the page load take a lot of time.

Is there a way i can load the contents of divs only on dropdownlist selection? (Please know that its the same php array which populates all div contents, so its already present on the page load)

Seeker88
  • 1
  • 2
  • add a change event (onchange) handler on the dropdownlist. – bobthedeveloper Apr 21 '14 at 08:06
  • Have you seen [this](http://stackoverflow.com/questions/2975521/show-hide-div-based-on-select-option-jquery) post? I think this may have already answered your question. This is, of course, assuming your drop down list is a traditional ` – danw Apr 21 '14 at 08:07
  • @Hatsjoem- that will not stop the code written inside the divs from executing. I am showing large amounts of data in every div and the foreach loop for going through the php array is taking alot of time. As i said,i have achieved the visibility part thru javascript. what i want to know is if i can somehow control the execution of content inside the divs. – Seeker88 Apr 21 '14 at 08:37
  • @danw - thanks for the suggestion. but that post again just tells how to control the visibility of divs. i want to control the php action of loading the content inside the divs, hence have a faster page load as i will load contents of only div1 and not div2 and 3. Hope i'm able to convey my problem. – Seeker88 Apr 21 '14 at 08:39
  • @Seeker88, hmm ok, I think I understand where you're coming from. I've never actually attempted to load page content in this way. The only thing that springs to mind is to assign the PHP array with your divs to a jQuery array ([explained here](http://stackoverflow.com/questions/15461417/how-do-you-assign-a-php-array-to-jquery-array)) and then load content from that jQuery array dynamically depending on the drop down selection. Hope this helps! – danw Apr 21 '14 at 16:18

0 Answers0