Jump to content


Photo

php drop down menu onchange...


  • Please log in to reply
1 reply to this topic

#1 saranda

saranda
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 May 2006 - 02:12 AM

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




#2 ansarka

ansarka
  • Members
  • PipPipPip
  • Advanced Member
  • 128 posts
  • LocationCochin, Kerala, India

Posted 04 May 2006 - 09:50 AM

[!--quoteo(post=371126:date=May 3 2006, 09:12 PM:name=saranda)--][div class=\'quotetop\']QUOTE(saranda @ May 3 2006, 09:12 PM) View Post[/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) View Post[/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
<?

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



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


EVEN THE WORD IMPOSSIBLE IS SAYING I' M' POSSIBLE




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users