list data from db and submit query?

hi everyone,

i am trying tot create the following, but i can't figure out how to do this.

A listbox (list/menu) gets names from db,
user selects a name from the list,
a query is send to db (where InputName=selected name),
output comes in texfields.

The problem for me is the following, how can i get the selected item from the list,
without using PHP_SELF?InputName=etc.

I've got something like this, but it has to function (if possible) without
getting the data from the browser...By the way, below code isn't working, anyway.

Is this possible? Anyone who kows how to this in a proper way?

Thanks in advance,


$result=mysql_query("select * from $dbTable3", $link);
$rowCheck = mysql_num_rows($result);

echo "<form name=\"CityName\" id=\"CityName\" action=\"$PHP_SELF\" method=\"get\">";
echo "<select name=\"InputName\" onchange=document.all.CityName.submit();>";
if($rowCheck > 0){

while($row = mysql_fetch_array($result)){

  //put in list

    echo "<option>".$row['Name']."</option>";
      echo "</select>";

        $InputName = addslashes($_GET['InputName']);
      $result=mysql_query("select * from $dbTable3 where Name = '$InputName'", $link);
      // get data from db etc..
         echo "fault";
end code
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This sort of thing is usually done with JavaScript... of course if your data is too big for that to be feasible, then you should use JavaScript to update the contents of a hidden IFRAME...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If the user selects a name from the list within the browser, how can you possibly get that data without going to the browser?  I'm confused.  Why do you have this requirement?

Typically in such a situation I would use Javscript's onChange to submit the data and reload the page with the new data passed along to PHP so it can handle the query and output the proper HTML.
Actually I just thought of a somewhat kludgy way.  The onChange, instead of submitting the data and having PHP reload the page with new info, could trigger a Javscript function.  Within that Javascript function you could already have a switch statement with all the corresponding data that you want outputted to the text field.  If the argument matches a case, that text is returned and displayed in your text box.  This solution is only feasible with small amounts of data though.  You don't want to have a gigantic Javascript function containing all your data if at all possible.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

which is what i suggested in the first place...
the difficulties can be smoothed however by using a hidden iframe...
with this solution the javascript doesn't load the list, it loads the iframe which contains the list.  after it's done loading then the javascript repopulates the dropdown
Haven't had the chance to use iframe before, but wouldn't it be safer to use "object" instead, since it's part of the 4.0 standard?  Plus, wouldn't using iframe to store the data be the same as coding it directly into the Javascript function as far as the amount of data that needs to be delivered before the page loads?  How about some sample code or pseudocode to demonstrate how it would be beneficial?

Either way, I think your solution should work.
with the iframe solution, you change the src as you change your text entry...

<INPUT Type="TEXT" OnChange="GetMyOptions" id="mytext" name="mytext">
<SELECT name="myselect">

<SCRIPT Language="JavaScript">
myframe.src = "" + encode(document.getElementById("mytext").text);

  function TwoBoxMove(a,b,c)
    //Andrew Komasinski 2004-10-25 This will move the items from one box to the other
           if (c == '>>') {
               var from = document.getElementById(a);
              var to = document.getElementById(b);
             } else
               var from = document.getElementById(b);
              var to = document.getElementById(a);
             while (from.selectedIndex > -1)
              var lastoption = new Option();
          lastoption.text = from.options[from.selectedIndex].text;
          lastoption.value = from.options[from.selectedIndex].value;
              to.options[to.length] = lastoption;
              from.options[from.selectedIndex] = null;

function reloadQ()



where shh is the name of the one being loaded in the iframe and has all of the options set to selected

(I use this code for some other stuff, edit it to fit your requirements exactly)
dwaxAuthor Commented:
Thanks guys,

The reason why i the info not from the browser, is because i  have wuite a heavy
flashmovie on the same page. With every form submit, the movie loads again...

One possible solution, not very neat is put it into frames...

The other one is using an iframe as you suggested. I will look into that a.s.ap.

thanks for your replies!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.