How do I update a dropdown menu when another dropd

2019-06-14 16:47发布

Basicly I want DROPDOWNMENU2 options to update when a option option from DROPDOWNMENU1 is selected.

Heres some info:

DROPDOWNMENU1 :

Web Development Graphics Windows

DROPDOWNMENU2 (for Web Development) :

PHP HTML CSS

DROPDOWNMENU2 (for Graphics) :

PNG JPEG ICO PSD

DROPDOWNMENU2 (for Windows) :

Seven Vista XP

Please help?

EDIT:

I'm trying to get this code to work

$('#topic2').change(function() {
$('#topic3').empty();
switch($(this).val()) {
    case 'Tutorials':
        $('#topic3')
            .append('<option>PHP</option>')
            .append('<option>HTML</option>')
            .append('<option>CSS</option>');
    case 'Graphics':
        // yada yada
        break;
    case 'Windows':
        // yada yada
        break;
}

});

HTML :

<form action="inc/post.php" method="POST">
Topic: 
<select name="topic">
<option>Web Development</option>
<option>Windows</option>
<option>Graphics</option>
</select>
/
<div id="topic2">
<select name="topic2" id="topic2">
<option>Tutorials</option>
<option>Article</option>
</select>
</div>
/
<div id="topic3">
<select name="topic3" id="topic3">
<option>Seven</option>
<option>Vista</option>
<option>XP</option>
</select>
</div>
<br /><Br />
Name:
<input type="text" name="name" />
<Br /><br />
Icon:
<input type="file" name="icon2" id="icon2"> 
<Br /><Br />
Content:
<textarea name="info" size="400"></textarea></div>
</div> 
</form>

2条回答
神经病院院长
2楼-- · 2019-06-14 17:12

I would use jQuery. Something like this...

$('#DROPDOWNMENU1').change(function() {
    $('#DROPDOWNMENU2').empty();
    switch($(this).val()) {
        case 'Web Development':
            $('#DROPDOWNMENU2')
                .append('<option>PHP</option>')
                .append('<option>HTML</option>')
                .append('<option>CSS</option>');
        case 'Graphics':
            // yada yada
            break;
        case 'Windows':
            // yada yada
            break;
    }
});
查看更多
Luminary・发光体
3楼-- · 2019-06-14 17:25
 <form name="x" id="x" action="x.php">
   <select name="DROPDOWNMENU1" id="DROPDOWNMENU1" 
     onchange="javascript:document.x.action='dropmenu.php';
     javascript:document.x.submit();">
    <option>select web development graphics windows</option>
    <?php
        $q=select * from development graphics windows;
        $result=msql_query($q);
        while($row = mysql_fetch_array($result)) {
            if($_POST["DROPDOWNMENU1"]==$row[web_development_id]){
    ?>
    <option value='<?php echo $row["web_development_id"]; ?>'selected>
        <?php echo $row["web_development_name"];?>
    </option>

in DROPDOWNMENU2 select data  where DROPDOWNMENU2.id=$_POST["DROPDOWNMENU1"];

I hope this answer help you

查看更多
登录 后发表回答