how can i insert drop down option values into the select

Discussion in 'PHP' started by macaela, Jan 15, 2012.

  1. #1
    Hi i have this form which the drop down options value is based on database query, i want to when onchange to add the drop down option value into the select value but i cant seem to be able to grab the drop down values, the drop down variable is $area_name i want to add from the drop down option to
    here
    echo " <select name=\"aid\" size=\"1\" onchange=\"jwplayer().load({file:'http://www.onfilm.biz/streaming/home/area_films/ ".$area_name.".flv'});jwplayer().play(true);\" style=\"width:160px\">  
    PHP:
        <form id="area_films" action="<?php echo $_SERVER['PHP_SELF']; ?>"  method="post" name="area_films">
                        <?php
                        //get the DB connection variables
                        include("includes/config.php");
                        //connect to DB
                        $connectionat = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT.");
                        $dbcat = @mysql_select_db($db_name, $connectionat) or die("Couldn't select DATABASE.");
                        //SELECT or FIND the same PASSWORD
                        $queryat="SELECT * FROM films_area WHERE (area_type = 'town' OR area_type = 'village' OR area_type = 'city') ORDER BY area_town ASC";
                        $resultat = mysql_query($queryat) or die("Couldn't execute QUERY - FIND Client TVs");
                        
    echo " <select name=\"aid\" size=\"1\" onchange=\"jwplayer().load({file:'http://www.onfilm.biz/streaming/home/area_films/ ".$area_name.".flv'});jwplayer().play(true);\" style=\"width:160px\"> 
                    <option value=\"none\">...location films...</option>";
                            while ($rowat = mysql_fetch_array($resultat))
                                {
                                    $area_id=$rowat['area_id'];
                                    $area_name=$rowat['area_town'];
                                    if($rowat['area_country'] == 'France')
                                {
                                     $area_name =  $area_name."(F)";
                                } 
                                    print("<option value='$area_id'>$area_name</option>");
                                }
                                    mysql_close($connectionat);
                            ?>
                </select>
                    <input style="width:70px;" type="submit" name="view" value="SEARCH" />
            </form>
    PHP:

     
    macaela, Jan 15, 2012 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,899
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Use ajax - it's easy with jquery and prototype. decide which one you want to use and then look at their examples.
     
    sarahk, Jan 15, 2012 IP
  3. w3goodies

    w3goodies Member

    Messages:
    94
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #3
    I am not quite sure what you want but what I understand is you want insert area_names into select and when the select change this javascript code runs: jwplayer().load({file:'http://www.onfilm.biz/streaming/home/area_films/ ".$area_name.".flv'});jwplayer().play(true);

    <form id="area_films" action="<?php echo $_SERVER['PHP_SELF']; ?>"  method="post" name="area_films">
                        <?php
                        //get the DB connection variables
                        include("includes/config.php");
                        //connect to DB
                        $connectionat = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT.");
                        $dbcat = @mysql_select_db($db_name, $connectionat) or die("Couldn't select DATABASE.");
                        //SELECT or FIND the same PASSWORD
                        $queryat="SELECT * FROM films_area WHERE (area_type = 'town' OR area_type = 'village' OR area_type = 'city') ORDER BY area_town ASC";
                        $resultat = mysql_query($queryat) or die("Couldn't execute QUERY - FIND Client TVs");
                        
    $Echos = " <select name='aid' size='1' onchange='jwplayer().load({file:\"http://www.onfilm.biz/streaming/home/area_films/\"+this.value+\".flv\"});jwplayer().play(true);' style='width:160px'> 
                    <option value='none'>...location films...</option>";
                            while ($rowat = mysql_fetch_array($resultat))
                                {
                                    $area_id=$rowat['area_id'];
                                    $area_name=$rowat['area_town'];
                                    if($rowat['area_country'] == 'France')
                                {
                                     $area_name =  $area_name."(F)";
                                } 
                                    $Echos .= "<option value='{$area_name}'>{$area_name}</option>";
                                }
    
                               echo $Echos;
                               mysql_close($connectionat);
                              ?>
                </select>
                    <input style="width:70px;" type="submit" name="view" value="SEARCH" />
            </form>
    PHP:
     
    w3goodies, Jan 15, 2012 IP