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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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