greensteam Posted April 2, 2012 Share Posted April 2, 2012 Hi, I am hoping someone can help me out with a slight issue I have with php and mySQL. I have an ajax-powered form with a select (dropdown) field populated through a php function. Based on the user-selected values in this field, data is displayed on the webpage; i.e. selected value 1 returns values x and y on the page. I am now trying to call additional data (value z) from a different table in the same database, and as before, use the selected values from the dropdown to display the data. For some reason, value z is not changing according to the user-selected value. This is my code: [The function to populate the select field] function kfl_get_funds_names() { $result = array(); $result['CDF'] = 'Crosby Dragon Fund'; $result['CPF'] = 'Crosby Phoenix Fund'; $result['AMZPIF'] = 'AMZ Plus Income Fund'; $result['KASBIIF'] = 'KASB Islamic Income Opportunity'; $result['KASBCPGF'] = 'KASB Capital Protected Gold Fund'; $result['KASBLF'] = 'KASB Income Opportunity Fund'; $result['KASBCF'] = 'KASB Cash Fund'; $result['KASBBF'] = 'KASB Asset Allocation Fund'; $result['KASBSMF'] = 'KASB Stock Market Fund'; return $result; } [the code calling and using the function to interact with the database] $funds_to_display = kfl_get_funds_names(); $current_symbol = key( $funds_to_display ); $current_nav_rates = kfl_get_latest_rates( $current_symbol ); [the code calling additional data, value z, from the database, and using the info in the select field to filter it] $cutoff = kfl_cutoff( $current_symbol ); The display of each of these items is as follows: <?php echo $current_nav_rates['nav_date']; ?> <?php echo $funds_to_display[$current_symbol]; ?> <?php echo $cutoff['cutoff']; ?> I can't get the $cutoff code to display the correct values. It picks up the first symbol to display and doesn't change with user selection. The code for the selection box, by the way: <select id="dailynav-funds" autocomplete="off" name="dnf"> <?php foreach ($funds_to_display as $fund_symbol => $fund_name) { echo '<option'; if( $fund_symbol == $current_symbol ) { echo ' selected="selected"'; } echo ' value="' . $fund_symbol . '">'; echo $fund_name; echo '</option>'; } ?> </select> I've tried to get data using $_GET['dnf'] into the cutoff code, but that throws up parse errors. What am I doing wrong, and how can I resolve this issue? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/260186-getting-data-based-on-a-dynamic-dropdown-list/ Share on other sites More sharing options...
Muddy_Funster Posted April 2, 2012 Share Posted April 2, 2012 can we see your javascript code please? Quote Link to comment https://forums.phpfreaks.com/topic/260186-getting-data-based-on-a-dynamic-dropdown-list/#findComment-1333512 Share on other sites More sharing options...
greensteam Posted April 2, 2012 Author Share Posted April 2, 2012 var KFL_Nav_Rates = function() { var nav_prev_selected; var init = function() { jQuery('#dailynav-funds').change(function(){ var selected_val = jQuery(this).val(); var selected_name = jQuery(this).find('option:selected').text(); var previous_selected = nav_prev_selected; if( selected_val != 0 ) { var self = this; jQuery(self).attr('disabled', true); jQuery(self).parents('.dailynav').fadeTo(0, 0.2); jQuery.ajax({ url:nav_rates_config.ajaxurl, type:'POST', data:{"action":nav_rates_config.action, "nav_symbol":selected_val}, dataType:'json', success:function( response ) { if( response.status == 1) { jQuery( '#price-offer' ).text( response.data.offer_price ); jQuery( '#price-red' ).text( response.data.nav_price ); jQuery( '.navdate' ).text( response.data.nav_date ); jQuery( '.fundname' ).text( selected_name ); if( typeof response.data.red_load != 'undefined' ) { jQuery( '#red-load span' ).text( response.data.red_load ); jQuery( '#red-load' ).show(); } else { jQuery( '#red-load' ).hide(); } } else { alert( 'Please try again later' ); jQuery(self).val(previous_selected); } }, error:function() { alert( 'Please try again later' ); jQuery(self).val(previous_selected); }, complete:function() { jQuery(self).parents('.dailynav').fadeTo(0, 1); jQuery(self).attr('disabled', false); } }); } }); jQuery('#dailynav-funds').focus(function(){ nav_prev_selected = jQuery(this).val(); }); }; return { init: init } }(); jQuery(function(){ KFL_Nav_Rates.init(); }); Quote Link to comment https://forums.phpfreaks.com/topic/260186-getting-data-based-on-a-dynamic-dropdown-list/#findComment-1333535 Share on other sites More sharing options...
Muddy_Funster Posted April 2, 2012 Share Posted April 2, 2012 eek, I've not used JQuery yet Quote Link to comment https://forums.phpfreaks.com/topic/260186-getting-data-based-on-a-dynamic-dropdown-list/#findComment-1333544 Share on other sites More sharing options...
greensteam Posted April 2, 2012 Author Share Posted April 2, 2012 Maybe someone else can help? Quote Link to comment https://forums.phpfreaks.com/topic/260186-getting-data-based-on-a-dynamic-dropdown-list/#findComment-1333575 Share on other sites More sharing options...
Jessica Posted April 2, 2012 Share Posted April 2, 2012 Is this a public site? If you can post a link, sometimes it's a lot easier to debug javascript when you can see it happening. And use firebug. If it's possible, please post a link as well. Quote Link to comment https://forums.phpfreaks.com/topic/260186-getting-data-based-on-a-dynamic-dropdown-list/#findComment-1333647 Share on other sites More sharing options...
greensteam Posted April 2, 2012 Author Share Posted April 2, 2012 It's not public yet - I don't want to post the link here and make it public. If you think you can help, I can send you the link by email. Quote Link to comment https://forums.phpfreaks.com/topic/260186-getting-data-based-on-a-dynamic-dropdown-list/#findComment-1333702 Share on other sites More sharing options...
Jessica Posted April 2, 2012 Share Posted April 2, 2012 If you want to PM it to me I'd be happy to look and try to debug, or you can install a javascript debugger which is what I would try, but I'm happy to help. Quote Link to comment https://forums.phpfreaks.com/topic/260186-getting-data-based-on-a-dynamic-dropdown-list/#findComment-1333722 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.