onchange populate next dropdown?

Discussion in 'JavaScript' started by mokimofiki, Aug 25, 2008.

  1. #1
    I know absolutly 0 javascript but would like to autopopulate an option box based on a previous options choice. This is what I have so far could any of you fine javascript ubers please help me out?


    in the header:
    <html>
    <head>
    <SCRIPT language=JavaScript>
    function reload(form)
    {
    var val=form.series.options[form.series.options.selectedIndex].value; 
    self.location='newquote.php?series=' + val ;
    }
    </script>
    </head>
    Code (markup):
    in the body:
    <form method="post" action="bridgestartnewquote.php">
    <table width="750" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="200" align="right">Series: 
    <?php 
    $result = mysql_query("SELECT series FROM series");
    print "<select name=series onchange=\"reload(this.form)\"> \n";
    print "<option></option>";
    while($row = mysql_fetch_assoc($result))
    {
    print "<option value=\"{$row['series']}\">{$row['series']}</option> \n";
    }
    print "</select> \n"; 
    ?>
    </td>
    <td width="275" align="right">Name: <input type="text" name="quotename" style="width: 150px"></td>
    <td width="275" align="right">Model: 
    <?php
    $result = mysql_query("SELECT model FROM models");
    print "<select name=model> \n";
    print "<option></option>";
    while($row = mysql_fetch_assoc($result))
    {
    print "<option value=\"{$row['model']}\">{$row['model']}</option> \n";
    }
    print "</select> \n"; 
    ?>
    </td>
    </tr>
    <td></td>
    <td></td>
    <td align="right"><input type="submit" value="Start Quote"></td>
    </table>
    </form>
    Code (markup):
    This is obviously a combination of php and javascript .... thank you for any help :)
     
    mokimofiki, Aug 25, 2008 IP
  2. jodarecode

    jodarecode Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This link may help

    http://www.dhtmlgoodies.com/index.html?whichScript=ajax_chained_select
     
    jodarecode, Aug 25, 2008 IP