?
Solved

DROP DOWN box no longer works in move from PHP to Javascript

Posted on 2013-06-24
13
Medium Priority
?
398 Views
Last Modified: 2014-05-11
We are trying to offload load from the server to the browser.  We have a drop down box with SELECT OPTION statements that have been transferred from PHP to Javascript.  drop-down box works the first time.  The updated SELECT is transferred back to PHP code with a JSON return.  Now, the dropdown box no longer "works."
0
Comment
Question by:ccbergman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39273762
Please wait while I put on my telepathy helmet so I can see your code through your eyes.... Hmmm no. Too much interference. Please post the code here instead and wrap it in [ code] ... [/ code] tags
0
 

Author Comment

by:ccbergman
ID: 39275325
function updateData()
{
	// update panel headers
	$.getJSON('/xml/xml.flights.counter.php', function (json)
	{
		var scheduledFlightData = json.scheduled;
		var scheduleViewDays = json.scheduleViewDays;
		var scheduleExpanded = json.scheduleExpanded;
		var php_Self = json.php_Self;

           var optIn = json.optIn;

		// Here we have the data structure that is returned from xml.flight.counters - so we can now pass this into
		// the new javascript function to display the scheduled pane.

		// As we make this same change to the other panes the calls to render them will occur here, meaning that we've now
		// limited the number of requests to draw the left panel of the page to just one
		genHTML_Scheduled(scheduledFlightData, showBlock, scheduleViewDays, scheduleExpanded, php_Self);
	
	});
}

Open in new window


[code]


function updateScheduled()
{
    $.getJSON('/xml/xml.flights.counter.php', function (json)
    {
        var scheduledFlightData = json.scheduled;
    });
}


function genHTML_Scheduled(scheduledFlightData, showBlock, scheduleViewDays, scheduleExpanded, php_Self)
{
        var SO = '';

        var o = '<table border="0" width="100%" style="border-collapse: collapse; border-color: #f0f0f0;" id="scheduledflights">';
        o += '<tr><th colspan="9" style="cursor:pointer"><b><? echo($current_flights_current_sched_text); ?></b></th></tr>';
        o += '<tr id="csf">';
    
        if (showBlock == "none")
        {
            SO = "no";
        }
        else
        {
            SO = "yes";
        }
     
        if(scheduleExpanded)
            o += '<td align="left" id="_hs"><a href="#" onclick="showNestedScheduled(false);"><? echo($current_flights_close_all_text); ?></a></td>';
        else
            o += '<td align="left" id="_hs"><a href="#" onclick="showNestedScheduled(true);"><? echo($current_flights_open_all_text); ?></a></td>';

        //The form below allows a user to select a number of days to see worth of flights
        o += '<td align="left" colspan="6"><form name="ScheduleViewDaysForm" method="POST" action="' + php_Self + '?window=queue&SO=' + SO + '&ScheduleViewDays=' + scheduleViewDays + '"><? echo($current_flights_show_text); ?>';
        o += '<select name="ScheduleViewDays" id="ScheduleViewDays" size="1" onchange="updateScheduled();">';

        if(scheduleViewDays == 0)
            o += '<option value="0" selected="selected">Infinite</option>';
        else
            o += '<option value="0"><? echo($current_flights_infinite_text); ?></option>';
        if (scheduleViewDays==1)
            o += '<option value="1" selected="selected">1</option>';
        else
            o += '<option value="1">1</option>';
        if (scheduleViewDays==2)
            o += '<option value="2" selected="selected">2</option>';
        else
            o += '<option value="2">2</option>';
        if (scheduleViewDays==3)
            o += '<option value="3" selected="selected">3</option>';
        else
            o += '<option value="3">3</option>';
        if (scheduleViewDays==4)
            o += '<option value="4" selected="selected">4</option>';
        else
            o += '<option value="4">4</option>';
        if (scheduleViewDays==5)
            o += '<option value="5" selected="selected">5</option>';
        else
            o += '<option value="5">5</option>';
        if (scheduleViewDays==6)
            o += '<option value="6" selected="selected">6</option>';
        else
            o += '<option value="6">6</option>';
        if (scheduleViewDays==7)
            o += '<option value="7" selected="selected">7</option>';
        else
            o += '<option value="7">7</option>';
        if (scheduleViewDays==8)
            o += '<option value="8" selected="selected">8</option>';
        else
            o += '<option value="8">8</option>';
        if (scheduleViewDays==9)
            o += '<option value="9" selected="selected">9</option>';
        else
            o += '<option value="9">9</option>';
        if (scheduleViewDays==10)
            o += '<option value="10" selected="selected">10</option>';
        else
            o += '<option value="10">10</option>';
        o += '</select><? echo($current_flights_days_text); ?>';
        o += '</form>';
        o += '</td>';
        o += '</tr>';
        o += '</table>';
   
        o += '<table border="0" width="100%" style="border-collapse: collapse; border-color: #f0f0f0;" id="scheduledflights_2">';
        o += '<tr>';
        o += '    <th width="300"><b><? echo($current_flights_reg_text); ?></b></th>';
        o += '    <th width="300"><b><? echo($current_flights_flight_number_text); ?></b></th>';
        o += '    <th width="300"><b><? echo($current_flights_from_text); ?></b></th>';
        o += '    <th width="300"><b><? echo($current_flights_at_text); ?></b></th>';
        o += '    <th width="300"><b><? echo($current_flights_to_text); ?></b></th>';
        o += '    <th width="300"><b><? echo($current_flights_at_text); ?></b></th>';
        o += '    <th width="300"><b><? echo($current_flights_bay_text); ?>Bay</b></th>';
        o += '</tr>';

 

        if (scheduledFlightData.length == 0)
        {
            o += '<tr><td align="centered" colspan="7"><? echo($current_flights_no_flights_scheduled_text); ?></td><td colspan="5">&nbsp;</td></tr>';
        }
        else
        {
            var aircraftID_old = '';

            $.each(scheduledFlightData, function (key, value)
            {
                if(aircraftID_old != value.AircraftID) 
                {
                    o += '<tr><td align="left" style="cursor:pointer" onClick="ShowFlights(event,' + value.AircraftID + ')"><b>' + value.AircraftID + '</b></td>';
                }
                else
                {
                    if (scheduleExpanded)
                    { 
                        o += '<tr id="' + value.AircraftID + key + '_div" class="hs"><td>&nbsp;</td>';
                    }  
                    else
                    {
                        o += '<tr id="' + value.AircraftID + key + '_div" class="hs" style="display:none"><td>&nbsp;</td>';
                    }              
                }
            
                o += '<td>' + value.FlightID + '</td>';
                o += '<td>' + value.DeparturePoint + '</td>';
                o += '<td>' + value.ScheduledDeparture + '</td>';
                o += '<td>' + value.ArrivalPoint + '</td>';
                o += '<td>' + value.ScheduledArrival  + '</td>';
                o += '<td>' + value.BayNumber + '</td>';
                o += '</tr>';
                aircraftID_old = value.AircraftID;
            });
        }

        o += '<tr id="scheduledFlightRows"></tr>';
        o += '</table>';
        // Update 'Scheduled' element
        $('#scheduled').html(o);
}

Open in new window

0
 
LVL 29

Expert Comment

by:fibo
ID: 39275499
Not sure what you expect from moving this dropdown list from php(on the server) to javascript (on the client)

In both cases your list will be populated on the server by php...
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39275524
Any errors in the console?

Does the url to the php work on its own (look in Chrome network tab)

BTW the code is not using jQuery to it's fullest. It is not optimal.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39275559
This snippet can replace your ifs


   o += '<option value="0" selected="selected">Infinite</option>';
   if (scheduleViewDays >0)  for (var i=1;i<=10;i++) {    
            var sel = i==scheduleViewDays?' selected="selected"':"";
            o += '<option value="'+i+'" '+sel+'>'+i+'</option>';
      }
   }
0
 

Author Comment

by:ccbergman
ID: 39276008
Thanks.  I will implement the code snippet to replace ifs,
and check on the url.
How can I optimize JQuery?
Thanks so much again.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39276143
Use $("#scheduled").append instead of that o += for example
0
 

Author Comment

by:ccbergman
ID: 39276380
Oh.  Ok.  :)
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 1100 total points
ID: 39276962
Ah, You might want

   if (scheduleViewDays >0)  for (var i=1;scheduleViewDays <i && i<=10;i++) {    
            var sel = i==scheduleViewDays?' selected="selected"':"";
            o += '<option value="'+i+'" '+sel+'>'+i+'</option>';
      }
   }
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40053802
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 40053803
0

Featured Post

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question