RE: question on <select>

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You'd have to take the value of the first select box in your form and pass
it to another script. You can do that by setting the form's ACTION property
to either GET or POST. Personally, I prefer POST.

In the script to which you submit your form, you can access the value of the
select object thusly: $_POST["varname"] and insert it into your query
however you want (using the appropriate input sanitization methods).

The important concept to understand here is that you cannot use PHP to drive
the contents of your second select object without a round-trip to the
server. Since PHP is a server-side technology, it HAS to work that way.

To make a client-side solution possible, you'd have to send ALL POSSIBLE
data to the page all at the same time then manipulate it with JavaScript.

You can make it LOOK like a dynamic solution by repeatedly resubmitting the
page to itself and using a combo platter of JS and PHP functions on the page
to handle data as it is progressively requested/sent, but you're still doing
a round-trip each time. It only looks like a client-side solution because
you submit to the same page all the time until certain conditions are
satisfied or your user clicks on a specific link or button.

If you're truly in search of a completely client-side solution using
JavaScript, I suggest checking the Javascript Boutique or Javascript Source
or any one of the hundreds of JS repositories you'll find in a google
search. There are many great examples of this problem such as selecting a
State in one select box then having the major cities in that State show up
in a second select object.

Hope this helped.

Rich



> -----Original Message-----
> From: hengameh [mailto:haghlara@xxxxxxxxxxxxxxxxx]
> Sent: Wednesday, May 12, 2004 11:34 AM
> To: 'Tony S. Wu'
> Cc: php-db@xxxxxxxxxxxxx
> Subject: RE:  question on <select>
> 
> 
> Well I am suing Java script to capture the selected item and 
> make it the
> value of my input box. But my problem is how to access this 
> information from
> this point on. Can someone please tell me how I can use the 
> selected item in
> my next SQL query?
> 
> -----Original Message-----
> From: Tony S. Wu [mailto:tonyswu@xxxxxxx] 
> Sent: Wednesday, May 12, 2004 11:07 AM
> To: hengameh
> Cc: php-db@xxxxxxxxxxxxx
> Subject: Re:  question on <select>
> 
> sounds like a job for JavaScript.
> 
> Tony S. Wu
> tonyswu@xxxxxxx
> 
> "Look into the right places, you can find some good offerings."
> http://homepage.mac.com/tonyswu/stw    - The perfect business.
> http://homepage.mac.com/tonyswu/tonyswu    - My web page.
> --------------------------------------------------------------
> ---------- 
> -------
> 
> 
> 
> On May 12, 2004, at 7:02 AM, hengameh wrote:
> 
> >
> >
> > Hello,
> >
> > I am very new to php and mysql so please be patient with 
> me. I don't  
> > even
> > know if I am using the right listing, but I hope someone 
> can help me!
> >
> >
> >
> > I need to create a <select> and the possible options are 
> from my mysql
> > database ( so far so good, I was able to find code to do that).
> >
> > Now I need to use the user selected option to drive the 
> options of me  
> > next
> > <select>.  I need to know how to capture what user selected 
> and how to  
> > pass
> > that around? I have used "onchange" attribute of the <select> to  
> > capture the
> > selected line but now how can I pass that to other php 
> scripts?  ( I  
> > need to
> > get the name of the country so that I can show a list of possible
> > state/province. I setting the value of the "newcountry" input to the
> > selected "country" but when I do echo $newcountry in 
> quicksearch.php,  
> > its
> > blank!!)
> >
> > Please help!!
> >
> >
> >
> > Thanks so much
> >
> >
> >
> > Here is what I have so far:
> >
> >
> >
> > Quicksearch.php file has the following code
> >
> > <br>
> >
> > <table class='form'>
> >
> >       <tr>
> >
> >             <th>Steps 1-4</th>
> >
> >       </tr>
> >
> >
> >
> >       <tr><td>
> >
> >             <form name="fcountry" method="post">
> >
> >                   <?php  require("country_build.php");?>
> >
> >                   <input type="text" name="newcountry" value="">
> >
> >
> >
> >       </form>
> >
> >
> >
> > </td></tr>
> >
> > </table>
> >
> > <!-- quicksearch.php   end -->
> >
> >
> >
> > <script language="JavaScript">
> >
> > <!--
> >
> > function changeMenu()
> >
> >   {
> >
> >       document.fcountry.newcountry.value =
> > 
> document.fcountry.country.options[document.fcountry.country.se
> lectedInd 
> > ex].v
> > alue;
> >
> >  }
> >
> > -->
> >
> > </script>
> >
> >
> >
> > Countrty_buil.php has the following
> >
> >
> >
> > <?php
> >
> > require_once("util.php");
> >
> >
> >
> > echo "<SELECT name=\"country\" class=\"input\"   
> > onchange=\"changeMenu()\">";
> >
> > //
> >
> > // initialize or capture the country variable
> >
> > $country = !isset($_REQUEST['country'])? "Select a country":
> > $_REQUEST['country'];
> >
> > $countrySQL = !isset($_REQUEST['country'])? "*": 
> $_REQUEST['country'];
> >
> > echo "<option value='$countrySQL' SELECTED>$country</option>";
> >
> > $query = "SELECT country FROM ". TABLECOUNTRY . " ORDER BY country  
> > ASC";
> >
> > // pconnect, select and query
> >
> > if ($link_identifier = mysql_pconnect(DBSERVERHOST, DBUSERNAME,  
> > DBPASSWORD))
> > {
> >
> >       if ( mysql_select_db(DBNAME, $link_identifier)) {
> >
> >             // run the query
> >
> >          $queryResultHandle = mysql_query($query, 
> $link_identifier) or  
> > die(
> > mysql_error() );
> >
> >          $ctrRows = mysql_num_rows($queryResultHandle); // 
> row counter
> >
> >             // if data exists then $rows will be 1 or greater
> >
> >             if( $ctrRows == 0 ) {
> >
> >                   echo"<option value='*'>No data  
> > found</option></select>";
> >
> >             }else{
> >
> >                   // build the select list
> >
> >                   while($row = 
> mysql_fetch_object($queryResultHandle))  
> > { //
> > grab a row
> >
> >                         echo "<option
> > value=\"$row->country\">$row->country</option>";
> >
> >                   }
> >
> >                   echo "</SELECT><br><br>";
> >
> >
> >
> >             }
> >
> >       }else{ // select
> >
> >             echo mysql_error();
> >
> >       }
> >
> > }else{ //pconnect
> >
> >       echo mysql_error();
> >
> > }
> >
> > ?>
> >
> >
> >
> >
> >
> >
> >
> >
> >
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux