Jump to content

php drop down menu onchange...


saranda

Recommended Posts

is there any posebility to put dropdown menu work in onchange eavent in php

something like this

<body>


<?
function une()
{
echo $zip;
}
?>
<select size="1" name="zip" id="zip" onchange="une()" />
<option value="value1"> Place of departure </option>
<option value="KKK">kkk</option>
<option value="KKK">bbb</option>
</select>
<input type="text" value="" id="K" name ="K">
</body>

</html>

or if you can achive this thing but in any other method please tell me
thnx....


Link to comment
https://forums.phpfreaks.com/topic/9021-php-drop-down-menu-onchange/
Share on other sites

[!--quoteo(post=371126:date=May 3 2006, 09:12 PM:name=saranda)--][div class=\'quotetop\']QUOTE(saranda @ May 3 2006, 09:12 PM) [snapback]371126[/snapback][/div][div class=\'quotemain\'][!--quotec--]
is there any posebility to put dropdown menu work in onchange eavent in php

something like this

<body>
<?
function une()
{
echo $zip;
}
?>
<select size="1" name="zip" id="zip" onchange="une()" />
<option value="value1"> Place of departure </option>
<option value="KKK">kkk</option>
<option value="KKK">bbb</option>
</select>
<input type="text" value="" id="K" name ="K">
</body>

</html>

or if you can achive this thing but in any other method please tell me
thnx....
[/quote]

You can use javascript to do this or you can you the new technology AJAX for the pourpose


[!--quoteo(post=371188:date=May 4 2006, 04:41 AM:name=anuka)--][div class=\'quotetop\']QUOTE(anuka @ May 4 2006, 04:41 AM) [snapback]371188[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You can use javascript to do this or you can you the new technology AJAX for the pourpose
[/quote]

Here is a sample code

index.php
[code]<?

// Edit these values {{{

$sql_host = 'localhost';
$sql_user = 'root';
$sql_pass = '';
$sql_db        = 'test';

// }}} End edit

?>

<script language="JavaScript">
    
    var arItems = new Array()

    arItems = [
    
    <?
    
    mysql_connect($sql_host, $sql_user, $sql_pass);
    mysql_select_db($sql_db);
    
    $qry = mysql_query('SELECT * FROM temp WHERE parent > 0');
    
    while ($row = mysql_fetch_array($qry)) {
        $arr.= '[' . $row['parent'] . ', ' . $row['id'] . ', \'' . $row['name'] . '\'],' . "\n\t";
    }
    
    $final = substr($arr, 0, -3);
    echo $final;
    
    ?>

    ]

    function fillItems( intStart ) {
        
        var fTypes = document.form1.types
        var fItems = document.form1.items
        var a = arItems
        var b, c, d, intItem, intType

        if ( intStart > 0 ) {
            for ( b = 0; b < a.length; b++ ) {
                if ( a[b][1] == intStart ) {
                intType = a[b][0];
            }
        }
        
        for ( c = 0; c < fTypes.length; c++ ) {
            if ( fTypes.options[ c ].value == intType ) {
                fTypes.selectedIndex = c;
            }
        }
    }
    
    if ( intType == null ) {
        intType = fTypes.options[ fTypes.selectedIndex ].value
    }

    fItems.options.length = 0;

    for ( d = 0; d < a.length; d++ ) {
        if ( a[d][0] == intType ) {
            fItems.options[ fItems.options.length ] = new Option( a[d][2], a[d][1] ); // no line-break here
        }

        if ( a[d][1] == intStart ) {
            fItems.selectedIndex = fItems.options.length - 1;
        }
    }
   }

</script>

<form name="form1">
<select name="types" onChange="fillItems(0)">
    <option value="#" selected="selected">Please select</option>
    <?
    mysql_connect($sql_host, $sql_user, $sql_pass);
    mysql_select_db($sql_db);
    $qry = mysql_query('SELECT * FROM temp WHERE parent = 0');
    while ($row = mysql_fetch_array($qry)) {
    ?>
        <option value="<?=$row['id'];?>"><?=$row['name'];?></option>
    <?
    }
    ?>
</select>

<select name="items"></select>
</form>

[/code]


sql file

CREATE TABLE `temp` (
`id` int(11) NOT NULL auto_increment,
`parent` int(11) NOT NULL default '0',
`name` varchar(45) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

--
-- Gegevens worden uitgevoerd voor tabel `temp`
--

INSERT INTO `temp` VALUES (1, 0, 'BMW');
INSERT INTO `temp` VALUES (2, 0, 'Mercedes');
INSERT INTO `temp` VALUES (3, 1, '3 Series');
INSERT INTO `temp` VALUES (4, 1, '5 Series');
INSERT INTO `temp` VALUES (5, 2, 'SLK');
INSERT INTO `temp` VALUES (6, 2, 'Maybach');


Hope this will help you

Archived

This topic is now archived and is closed to further replies.

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