natasha_thomas Posted March 10, 2011 Share Posted March 10, 2011 Folks, I am trying to grab the value selected in a Dropdown, with $_GET['q']. Then i am echoing the grabbed value. Funny thing is, when i select value from HTML dropdown (onchange="location=this.value"), and when a new value is selcted, it appaears in url like this: http://www.abc.com/?search=selected-value.html But when i try to grab and echo the value of 'q' it gets passed only when i refresh the page and not when i change my selecting in dropdown. Am not sure whats happening, can someone help me on this? Cheers NT Quote Link to comment https://forums.phpfreaks.com/topic/230254-funny-_get-passed-only-when-refreshed/ Share on other sites More sharing options...
flolam Posted March 10, 2011 Share Posted March 10, 2011 your onchange event doesn't send any data back to the server, where the php file is. It only changes the location at the client-side. You will either have to use ajax or use normal links Quote Link to comment https://forums.phpfreaks.com/topic/230254-funny-_get-passed-only-when-refreshed/#findComment-1185762 Share on other sites More sharing options...
Alex1646 Posted March 10, 2011 Share Posted March 10, 2011 Sense php is server side, it only gets updated when the browser calls for the page. This is because the PHP gets interpreted in the server not the browser. I am pretty sure Javascript that can let you refresh when something happens. Quote Link to comment https://forums.phpfreaks.com/topic/230254-funny-_get-passed-only-when-refreshed/#findComment-1185763 Share on other sites More sharing options...
natasha_thomas Posted March 11, 2011 Author Share Posted March 11, 2011 your onchange event doesn't send any data back to the server, where the php file is. It only changes the location at the client-side. You will either have to use ajax or use normal links Thanks to both of you, but it made my job lot tougher, i know nothing of Ajex and JS. Here is the actual code i am using for Dropdown. <select onchange="location=this.value"> <option value=""> Select Brand/Mfg</option> <?php foreach($mfg as $lolachild): ?> <option value="<?php echo $host.str_replace(' ','-',$lolachild).'.html'; ?>"><?php echo ucwords($lolachild); ?> </option> <?php endforeach; ?> </select> How can i change this to JS? Can you please help me editing this code? Cheers Natasha T Quote Link to comment https://forums.phpfreaks.com/topic/230254-funny-_get-passed-only-when-refreshed/#findComment-1185998 Share on other sites More sharing options...
darkfreaks Posted March 11, 2011 Share Posted March 11, 2011 this should explain how to make a select box using Ajax http://bonrouge.com/~chain_select_ajax Quote Link to comment https://forums.phpfreaks.com/topic/230254-funny-_get-passed-only-when-refreshed/#findComment-1186000 Share on other sites More sharing options...
natasha_thomas Posted March 11, 2011 Author Share Posted March 11, 2011 this should explain how to make a select box using Ajax http://bonrouge.com/~chain_select_ajax Hi, i do not wish to use Ajax, coz it does not load the page again, and i have some other PHP Function which works only of the page is loaded. I think Javascript should rather solve my problem. What code change do i need to make it work? Quote Link to comment https://forums.phpfreaks.com/topic/230254-funny-_get-passed-only-when-refreshed/#findComment-1186003 Share on other sites More sharing options...
darkfreaks Posted March 11, 2011 Share Posted March 11, 2011 will this work? Html: <form id="aform"> <select id="mymenu" size="1"> <option value="nothing" selected="selected">Select a site</option> <option value="http://www.dynamicdrive.com">Dynamic Drive</option> <option value="http://www.codingforums.com">Coding Forums</option> <option value="http://www.cssdrive.com">CSS Drive</option> </select> </form> Javascript: <script type="text/javascript"> var selectmenu=document.getElementById("mymenu") selectmenu.onchange=function(){ //run some code when "onchange" event fires var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu" if (chosenoption.value!="nothing"){ window.open(chosenoption.value, "", "") //open target site (based on option's value attr) in new window } } </script> Quote Link to comment https://forums.phpfreaks.com/topic/230254-funny-_get-passed-only-when-refreshed/#findComment-1186004 Share on other sites More sharing options...
natasha_thomas Posted March 11, 2011 Author Share Posted March 11, 2011 will this work? Html: <form id="aform"> <select id="mymenu" size="1"> <option value="nothing" selected="selected">Select a site</option> <option value="http://www.dynamicdrive.com">Dynamic Drive</option> <option value="http://www.codingforums.com">Coding Forums</option> <option value="http://www.cssdrive.com">CSS Drive</option> </select> </form> Javascript: <script type="text/javascript"> var selectmenu=document.getElementById("mymenu") selectmenu.onchange=function(){ //run some code when "onchange" event fires var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu" if (chosenoption.value!="nothing"){ window.open(chosenoption.value, "", "") //open target site (based on option's value attr) in new window } } </script> Based on this, i modified my code as below: <form id="aform"> <select id="mymenu" size="1"> <option value=""> Select Category</option> <?php foreach($searchWords as $lolachild): ?> <option value="<?php echo $host.str_replace(' ','-',$lolachild).'.html'; ?>"><?php echo ucwords($lolachild); ?> </option> <?php endforeach; ?> </select> </form> <script type="text/javascript"> var selectmenu=document.getElementById("mymenu") selectmenu.onchange=function(){ //run some code when "onchange" event fires var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu" if (chosenoption.value!="nothing"){ window.open(chosenoption.value, "", "") //open target site (based on option's value attr) in new window } } </script> But this code also do not let me grab the value of $_GET['q'] on the new page. :'( :'( :'( Quote Link to comment https://forums.phpfreaks.com/topic/230254-funny-_get-passed-only-when-refreshed/#findComment-1186026 Share on other sites More sharing options...
darkfreaks Posted March 11, 2011 Share Posted March 11, 2011 you need Ajax then http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/ Quote Link to comment https://forums.phpfreaks.com/topic/230254-funny-_get-passed-only-when-refreshed/#findComment-1186028 Share on other sites More sharing options...
natasha_thomas Posted March 12, 2011 Author Share Posted March 12, 2011 I tired to make the below code, not sure what is wrong in that.. <select id="items" onselect="javascript:reloadPage(this)"> <?php foreach($searchWords as $lolachild): ?> <option value="<?php echo $host.str_replace(' ','-',$lolachild).'.html'; ?>"><?php echo ucwords($lolachild); ?> </option> <?php endforeach; ?> </select> <script type="text/javascript"><!-- function reloadPage(id) { document.location.href = location.href + id.value; } --></script> Quote Link to comment https://forums.phpfreaks.com/topic/230254-funny-_get-passed-only-when-refreshed/#findComment-1186520 Share on other sites More sharing options...
darkfreaks Posted March 12, 2011 Share Posted March 12, 2011 if you want to change it just google a java script refresh function it should refresh the page url. http://grizzlyweb.com/webmaster/javascripts/refresh.asp Quote Link to comment https://forums.phpfreaks.com/topic/230254-funny-_get-passed-only-when-refreshed/#findComment-1186525 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.