linked dropdownboxes, php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ward

    linked dropdownboxes, php

    Hi,

    Consider a window with 2 linked dropdownboxes, dynamically
    fed from a dbase.

    One technique to implement this would be to use an onchange
    event on the first box, then have the script call itself again,
    this time with a GET variable, calling the db for a 2nd time to
    populate the 2nd dropdownbox. (using PHP)

    That's fine when you have a local connection to a db, as you have
    little connection-setup-costs, and only minor image flicker.


    I'm not, so I'm trying to do this :

    My PHPscript calls the db ONCE, then it writes the <options> for
    the second dropdownbox in a javascript function 'showlinks'.
    The opt function does the actual document.writin g
    <head>
    ...
    function showlinks() {
    if (hoofdregio =='ASSE') {
    opt('xxx','Alle maal');
    opt('yyy','ASSE ');
    opt('zzz','BRU' );}

    if (hoofdregio =='BKH') {
    opt('xxx','Alle maal');
    ...
    }

    </head>


    My problem is that for this to work, creating the 2nd dropdownbox
    has to be done in javascript completely like so :


    document.write( '<FORM NAME="subregios "' + 'onSubmit="retu rn load
    (document.subre gios.subregio)" >');
    document.write( '<SELECT NAME="subregio" >');
    document.write( '<OPTION SELECTED>Allema al<\/option>');
    showlinks();
    document.write( '<\/SELECT>');
    document.write( '<INPUT TYPE="SUBMIT" VALUE="Go">');
    document.write( '<\/FORM>');


    What I would like to do is this :

    <select name="subregio" >
    <option selected>allema al</option>
    <script>showlin ks();</script>
    </select>



    Any ideas ?


    thx

    Ward




  • Ward

    #2
    Re: linked dropdownboxes, php

    Ward <king.albert.II @for.president. com> wrote in
    news:Xns93FE744 FB33D9wardgermo npreverhels@195 .130.132.70:
    [color=blue]
    > Hi,
    >
    > Consider a window with 2 linked dropdownboxes, dynamically
    > fed from a dbase.
    >
    > One technique to implement this would be to use an onchange
    > event on the first box, then have the script call itself again,
    > this time with a GET variable, calling the db for a 2nd time to
    > populate the 2nd dropdownbox. (using PHP)
    >
    > That's fine when you have a local connection to a db, as you have
    > little connection-setup-costs, and only minor image flicker.
    >
    >
    > I'm not, so I'm trying to do this :
    >
    > My PHPscript calls the db ONCE, then it writes the <options> for
    > the second dropdownbox in a javascript function 'showlinks'.
    > The opt function does the actual document.writin g
    ><head>
    > ..
    > function showlinks() {
    > if (hoofdregio =='ASSE') {
    > opt('xxx','Alle maal');
    > opt('yyy','ASSE ');
    > opt('zzz','BRU' );}
    >
    > if (hoofdregio =='BKH') {
    > opt('xxx','Alle maal');
    > ..
    > }
    >
    ></head>
    >
    >
    > My problem is that for this to work, creating the 2nd dropdownbox
    > has to be done in javascript completely like so :
    >
    >
    > document.write( '<FORM NAME="subregios "' + 'onSubmit="retu rn load
    > (document.subre gios.subregio)" >');
    > document.write( '<SELECT NAME="subregio" >');
    > document.write( '<OPTION SELECTED>Allema al<\/option>');
    > showlinks();
    > document.write( '<\/SELECT>');
    > document.write( '<INPUT TYPE="SUBMIT" VALUE="Go">');
    > document.write( '<\/FORM>');
    >
    >
    > What I would like to do is this :
    >
    ><select name="subregio" >
    ><option selected>allema al</option>
    ><script>showli nks();</script>
    ></select>
    >
    >
    >
    > Any ideas ?
    >
    >
    > thx
    >
    > Ward
    >
    >
    >
    >
    >[/color]

    Forget it, problem solved.

    Ward

    Comment

    • danjam
      New Member
      • Jun 2006
      • 7

      #3
      Here's a modular, customizable script for linked select boxes, from WebOnWebOff.com .

      You can specify what options to display at the start, or options to display when no options exist for the selected value.



      Hope this helps...

      Comment

      Working...