Jump to content

FUNNY: $_GET[] passed only when refreshed.... :-(


natasha_thomas

Recommended Posts

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:

 

 

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

 

:'( :'( :'(

 

 

Link to comment
Share on other sites

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>

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.