Re: How to code in PHP an onchange event in a <select>?

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

 




On 2010-11-04, at 4:23 PM, TomÃs Corrales Lemoine <tomas@xxxxxxxxxxxxxxxxxxxx> wrote:

> Hi, List,
> 
>  
> 
> I have this two files (âindex.phpâ and âinclude.phpâ). They both work fine, but I want to substitute the code for de onchange event in the <select> tag. Can I use PHP to code this event? How?
> 
>  
> 
> Thanks.
> 
>  
> 
>  
> 
>  
> 
> index.php:
> 
>  
> 
> <?php
> 
>  
> 
> echo '<html><body>';
> 
>  
> 
> include_once 'include.php';
> 
>  
> 
> $mysql_link = tcl_MySQL_ConnectToServer('localhost', 'user', 'password');
> 
>  
> 
> tcl_MySQL_OpenDataBase($mysql_link, 'production');
> 
>  
> 
> $query = 'SELECT DISTINCT recipe.product_id, product.description FROM recipe, product WHERE recipe.product_id = product.product_id ORDER BY product.description';
> 
> $result = tcl_MySQL_DataQuery($mysql_link, $query);
> 
>  
> 
> tcl_FillComboBox($result, 'Product', 'product_id', 'description', 'alert(\'Alert Message\')');
> 
>  
> 
> tcl_MySQL_CloseConnection($mysql_link);
> 
>  
> 
> echo '</body></html>';
> 
>  
> 
> ?>
> 
>  
> 
>  
> 
>  
> 
> include.php:
> 
>  
> 
> <?php
> 
>  
> 
> function tcl_MySQL_CloseConnection($link) {
> 
>       mysql_close($link);
> 
> }
> 
>  
> 
> function tcl_MySQL_ConnectToServer($host, $user, $password) {
> 
>       $link = mysql_connect($host, $user, $password);
> 
>       if (!$link) {
> 
>             die('No se pudo conectar: '.mysql_error());
> 
>       }
> 
>       echo '<h3>User '.strtoupper($user).' connected to MySQL server.</h3>';
> 
>       return $link;
> 
> }
> 
>  
> 
> function tcl_MySQL_DataQuery($link, $query) {
> 
>       return mysql_query($query, $link);
> 
> }
> 
>  
> 
> function tcl_MySQL_OpenDataBase($link, $database) {
> 
>       mysql_select_db($database, $link);
> 
> }
> 
>  
> 
> function tcl_FillComboBox($result, $label, $col1, $col2, $onchange) {
> 
>       echo '<label>'.$label.'</label><select onchange="'.$onchange.'"><option value="">';
> 
>       while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
> 
>             echo '<option value="'.$line[$col1].'">'.$line[$col2];
> 
>       }
> 
>       echo '</select>';
> 
> }
> 
>  
> 
> ?>
> 
>  
> 
> 
> -- 
> Aeropuerto Internacional Frank PaÃs GarcÃa de HolguÃn.
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


Ajax back to the server to run the php

Bastien Koert

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux