Set Value of Form Objects Without Submitting?

Discussion in 'HTML' started by HumanJHawkins, Feb 17, 2004.

  1. Hi,

    We have a project where a form needs to have several fields... Drop down
    lists and text boxes mostly. The problem is that one of the drop down menus
    needs to be populated based on the value in another drop down menu.

    So, we want to use "onChange" for the first field to run a query to fill the
    second field. But all of the examples we have found require us to submit the
    form before the data is accessible. If we submit the form, then any of the
    other fields that might have been filled out are lost.

    Is there any way to say something like:

    onChange = Get the value of the changed item and run a query. Then fill this
    other drop down menu with the returned results of that query.

    Thanks!
    HumanJHawkins, Feb 17, 2004
    #1
    1. Advertising

  2. HumanJHawkins

    Cletus Lee Guest

    In article <EFrYb.7469$>,
    says...
    > Hi,
    >
    > We have a project where a form needs to have several fields... Drop down
    > lists and text boxes mostly. The problem is that one of the drop down menus
    > needs to be populated based on the value in another drop down menu.
    >
    > So, we want to use "onChange" for the first field to run a query to fill the
    > second field. But all of the examples we have found require us to submit the
    > form before the data is accessible. If we submit the form, then any of the
    > other fields that might have been filled out are lost.
    >
    > Is there any way to say something like:
    >
    > onChange = Get the value of the changed item and run a query. Then fill this
    > other drop down menu with the returned results of that query.


    This is normally managed on the client side using javascript.

    Using if{} or switch{} logic to set a value like
    document.<formname>.<formfieldname>.value = 'what ever it needs to be';

    --

    Cletus D. Lee
    http://www.clee.org
    - Bellaire, TX USA -
    Cletus Lee, Feb 17, 2004
    #2
    1. Advertising

  3. HumanJHawkins wrote:

    > Hi,
    >
    > We have a project where a form needs to have several fields... Drop down
    > lists and text boxes mostly. The problem is that one of the drop down menus
    > needs to be populated based on the value in another drop down menu.
    >
    > So, we want to use "onChange" for the first field to run a query to fill the
    > second field. But all of the examples we have found require us to submit the
    > form before the data is accessible. If we submit the form, then any of the
    > other fields that might have been filled out are lost.
    >
    > Is there any way to say something like:
    >
    > onChange = Get the value of the changed item and run a query. Then fill this
    > other drop down menu with the returned results of that query.
    >
    > Thanks!
    >
    >

    look on the macromedia developer's exchange by a tag called
    CF_TwoSelectsRelated,
    http://www.macromedia.com/cfusion/e...snid=sn106&itemnumber=1&extid=1000288&catid=0

    From the site:
    Puts two SELECT form elements onto the current page, which contain
    choices from any query. The two SELECTs are related -- when the user
    chooses an item from the first SELECT, the items from the second SELECT
    are "filled" with corresponding items for the user to choose from.

    hth,
    larry

    --

    Larry C. Lyons

    ========================================================
    Life is Complex. It has both real and imaginary parts.
    ========================================================
    Chaos, Panic and Disorder. My work here is done.
    Larry C. Lyons, Feb 18, 2004
    #3
  4. HumanJHawkins

    Paul Dempsey Guest

    "HumanJHawkins" <> wrote in message news:<EFrYb.7469$>...
    >
    > We have a project where a form needs to have several fields... Drop down
    > lists and text boxes mostly. The problem is that one of the drop down menus
    > needs to be populated based on the value in another drop down menu.
    >
    > So, we want to use "onChange" for the first field to run a query to fill the
    > second field. But all of the examples we have found require us to submit the
    > form before the data is accessible. If we submit the form, then any of the
    > other fields that might have been filled out are lost.
    >
    > Is there any way to say something like:
    >
    > onChange = Get the value of the changed item and run a query. Then fill this
    > other drop down menu with the returned results of that query.
    >


    You can use JavaScript to set values in a second select element based
    on a change in the first select element. You can't do this with a
    query to the server without leaving the page you are on (that is,
    submitting the form).

    There are some options to do this. You can use ColdFusion on the form
    to populate JavaScript arrays, so the onChange will work as you
    specified. This could be a problem if the number of possible select
    items is very large.

    Another option is to do a multi-part form. Based on selections made in
    part 1, certain options are made available in part 2. You can pass
    form data along from one part to another with hidden fields, or you
    can update the database as you go along.

    Paul Dempsey
    Dickinson College
    Paul Dempsey, Feb 18, 2004
    #4
  5. HumanJHawkins

    Ci-Ci Mills Guest

    I usually go with WDDX for a problem like this. Only one trip to the
    DB and it is fast.

    Here is an example:
    http://www.procept.net/coldfusion/tutorials/dynSelect/dynSelect_explainClient.cfm

    "Larry C. Lyons" <> wrote in message news:<HXzYb.39155$>...
    > HumanJHawkins wrote:
    >
    > > Hi,
    > >
    > > We have a project where a form needs to have several fields... Drop down
    > > lists and text boxes mostly. The problem is that one of the drop down menus
    > > needs to be populated based on the value in another drop down menu.
    > >
    > > So, we want to use "onChange" for the first field to run a query to fill the
    > > second field. But all of the examples we have found require us to submit the
    > > form before the data is accessible. If we submit the form, then any of the
    > > other fields that might have been filled out are lost.
    > >
    > > Is there any way to say something like:
    > >
    > > onChange = Get the value of the changed item and run a query. Then fill this
    > > other drop down menu with the returned results of that query.
    > >
    > > Thanks!
    > >
    > >

    > look on the macromedia developer's exchange by a tag called
    > CF_TwoSelectsRelated,
    > http://www.macromedia.com/cfusion/e...snid=sn106&itemnumber=1&extid=1000288&catid=0
    >
    > From the site:
    > Puts two SELECT form elements onto the current page, which contain
    > choices from any query. The two SELECTs are related -- when the user
    > chooses an item from the first SELECT, the items from the second SELECT
    > are "filled" with corresponding items for the user to choose from.
    >
    > hth,
    > larry
    Ci-Ci Mills, Feb 18, 2004
    #5
  6. HumanJHawkins

    Cam Penner Guest

    In article <f7ec4036.0402181313.196385a6
    @posting.google.com>, says...
    > I usually go with WDDX for a problem like this. Only one trip to the
    > DB and it is fast.
    >
    > Here is an example:
    > http://www.procept.net/coldfusion/tutorials/dynSelect/dynSelect_explainClient.cfm


    Presuming, of course, that there is a small number of small
    results sets.

    WDDX is very expensive on bandwidth. (compared to regular
    lists) If you have a large number of result sets, or a
    large amount of data, WDDX becomes very unwieldily.

    --
    Cam
    Cam Penner, Feb 19, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Smithz
    Replies:
    3
    Views:
    34,619
    mokker
    Oct 30, 2009
  2. Fox
    Replies:
    2
    Views:
    269
    Randy Rahbar
    Sep 10, 2003
  3. Marco Alting
    Replies:
    7
    Views:
    505
    Thomas 'PointedEars' Lahn
    Oct 30, 2003
  4. Tauqir
    Replies:
    3
    Views:
    109
    Tauqir
    Aug 5, 2005
  5. klikic
    Replies:
    3
    Views:
    125
    klikic
    Dec 10, 2006
Loading...

Share This Page