creating dynamic select list from DB query

Discussion in 'Javascript' started by Pasquale, Jun 8, 2004.

  1. Pasquale

    Pasquale Guest

    Hello,

    I wondering if there is a way to dynamically update a select list with
    javascript from a database query without having to reload the page to
    update the list?
     
    Pasquale, Jun 8, 2004
    #1
    1. Advertising

  2. Pasquale

    kaeli Guest

    In article <>,
    enlightened us with...
    > Hello,
    >
    > I wondering if there is a way to dynamically update a select list with
    > javascript from a database query without having to reload the page to
    > update the list?
    >
    >


    With client-side javascript alone, no.
    With an ActiveX or COM add-in, yes, but the solutions tend to be IE
    only.
    With client-side javascript tag that uses a source of a server-side file
    that outputs javascript, yes.

    I'll assume you'd like that last one.
    <script type="text/javascript"
    src="http://www.myserver.com/myDirectory/cgi-bin/myCGI.pl"></script>

    myCGI.pl would need to output the javascript that updates the select
    with the proper header info that says it's text/javascript.
    There's lots of posts for how to dynamically generate / change select
    boxes, so I'll not post that bit. Google has plenty of hits for the
    topic as well.

    --
    --
    ~kaeli~
    Doing my part to piss off the Religious Right.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
     
    kaeli, Jun 8, 2004
    #2
    1. Advertising

  3. Pasquale

    Pasquale Guest

    I am using the following code below in a pop-up window to update the
    select list in the opening window. Works fine in Netscape 7.02, but I
    get a "server threw an exception" error when using it in IE 6.0.2800.

    This code is supposed to avoid the "server threw an exception" error.

    Any suggestions.


    <CFSET dtkey = "1">
    <SCRIPT type="text/javascript">
    function Venue() {
    opener.document.crsadd.venue1.options.length = 0;
    opener.theoption = new Option('Select Venue...','',1);
    opener.document.crsadd.venue1[opener.document.crsadd.venue1.length] =
    opener.theoption;

    <CFOUTPUT query="venue">
    <CFIF venuename EQ "na">
    opener.theoption = new Option('#address#-#cityname#,
    #relprovID#','#venueID#');
    opener.document.crsadd.venue1[opener.document.crsadd.venue1.length] =
    opener.theoption;
    <CFSET dtkey = #IncrementValue(dtkey)#>
    <CFELSE>
    opener.theoption = new Option('#venuename#-#address#-#cityname#,
    #relprovID#','#venueID#');
    opener.document.crsadd.venue1[opener.document.crsadd.venue1.length] =
    opener.theoption;
    <CFSET dtkey = #IncrementValue(dtkey)#>
    </CFIF>
    </CFOUTPUT>
    }
    Venue();
    </SCRIPT>


    kaeli wrote:
    > In article <>,
    > enlightened us with...
    >
    >>Hello,
    >>
    >>I wondering if there is a way to dynamically update a select list with
    >>javascript from a database query without having to reload the page to
    >>update the list?
    >>
    >>

    >
    >
    > With client-side javascript alone, no.
    > With an ActiveX or COM add-in, yes, but the solutions tend to be IE
    > only.
    > With client-side javascript tag that uses a source of a server-side file
    > that outputs javascript, yes.
    >
    > I'll assume you'd like that last one.
    > <script type="text/javascript"
    > src="http://www.myserver.com/myDirectory/cgi-bin/myCGI.pl"></script>
    >
    > myCGI.pl would need to output the javascript that updates the select
    > with the proper header info that says it's text/javascript.
    > There's lots of posts for how to dynamically generate / change select
    > boxes, so I'll not post that bit. Google has plenty of hits for the
    > topic as well.
    >
     
    Pasquale, Jun 15, 2004
    #3
  4. Pasquale

    Grant Wagner Guest

    You can not manipulate the contents of a <select> in another window directly
    in Internet Explorer. Write a function in "opener" that adds the <option> to
    the <select> with your chosen parameters, then call that function.

    In "opener":

    function clearSelect(formName, selectName) {
    document.forms[formName].elements[selectName].options.length = 0;
    }
    function addOption(formName, selectName, optionText, optionValue, selected,
    defaultSelected) {
    var theSelect = document.forms[formName].elements[selectName];
    theSelect.options[theSelect.length] = new Option(optionText, optionValue,
    selected, defaultSelected);
    }

    In the new window:

    <CFSET dtkey = "1">
    <SCRIPT type="text/javascript">
    function Venue() {
    if (opener && opener.clearSelect && opener.addOption) {
    opener.clearSelect('crsadd', 'venue1');
    opener.addOption('crsadd', 'venue1', 'Select Venue...', '', true);

    <CFOUTPUT query="venue">
    <CFIF venuename EQ "na">
    opener.addOption('crsadd', 'venue1',
    '#address#-#cityname#,#relprovID#','#venueID#');
    <CFSET dtkey = #IncrementValue(dtkey)#>
    <CFELSE>
    opener.addOption('crsadd', 'venue1',
    '#venuename#-#address#-#cityname#,#relprovID#','#venueID#');
    <CFSET dtkey = #IncrementValue(dtkey)#>
    </CFIF>
    </CFOUTPUT>
    }
    Venue();
    </SCRIPT>

    Untested, I think I probably made a mistake somewhere translating what you
    were doing into the opener callback, but you should have the basic idea. Don't
    try to manipulate opener directly, call functions in opener that do what you
    want.

    Pasquale wrote:

    > I am using the following code below in a pop-up window to update the
    > select list in the opening window. Works fine in Netscape 7.02, but I
    > get a "server threw an exception" error when using it in IE 6.0.2800.
    >
    > This code is supposed to avoid the "server threw an exception" error.
    >
    > Any suggestions.
    >
    > <CFSET dtkey = "1">
    > <SCRIPT type="text/javascript">
    > function Venue() {
    > opener.document.crsadd.venue1.options.length = 0;
    > opener.theoption = new Option('Select Venue...','',1);
    > opener.document.crsadd.venue1[opener.document.crsadd.venue1.length] =
    > opener.theoption;
    >
    > <CFOUTPUT query="venue">
    > <CFIF venuename EQ "na">
    > opener.theoption = new Option('#address#-#cityname#,
    > #relprovID#','#venueID#');
    > opener.document.crsadd.venue1[opener.document.crsadd.venue1.length] =
    > opener.theoption;
    > <CFSET dtkey = #IncrementValue(dtkey)#>
    > <CFELSE>
    > opener.theoption = new Option('#venuename#-#address#-#cityname#,
    > #relprovID#','#venueID#');
    > opener.document.crsadd.venue1[opener.document.crsadd.venue1.length] =
    > opener.theoption;
    > <CFSET dtkey = #IncrementValue(dtkey)#>
    > </CFIF>
    > </CFOUTPUT>
    > }
    > Venue();
    > </SCRIPT>
    >
    > kaeli wrote:
    > > In article <>,
    > > enlightened us with...
    > >
    > >>Hello,
    > >>
    > >>I wondering if there is a way to dynamically update a select list with
    > >>javascript from a database query without having to reload the page to
    > >>update the list?
    > >>
    > >>

    > >
    > >
    > > With client-side javascript alone, no.
    > > With an ActiveX or COM add-in, yes, but the solutions tend to be IE
    > > only.
    > > With client-side javascript tag that uses a source of a server-side file
    > > that outputs javascript, yes.
    > >
    > > I'll assume you'd like that last one.
    > > <script type="text/javascript"
    > > src="http://www.myserver.com/myDirectory/cgi-bin/myCGI.pl"></script>
    > >
    > > myCGI.pl would need to output the javascript that updates the select
    > > with the proper header info that says it's text/javascript.
    > > There's lots of posts for how to dynamically generate / change select
    > > boxes, so I'll not post that bit. Google has plenty of hits for the
    > > topic as well.
    > >


    --
    | Grant Wagner <>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *
    http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

    * Internet Explorer DOM Reference available at:
    *
    http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    * http://www.mozilla.org/docs/web-developer/upgrade_2.html
     
    Grant Wagner, Jun 15, 2004
    #4
  5. Pasquale

    Pasquale Guest

    Thanks Grant. It works beautifully.

    Grant Wagner wrote:
    > You can not manipulate the contents of a <select> in another window directly
    > in Internet Explorer. Write a function in "opener" that adds the <option> to
    > the <select> with your chosen parameters, then call that function.
    >
    > In "opener":
    >
    > function clearSelect(formName, selectName) {
    > document.forms[formName].elements[selectName].options.length = 0;
    > }
    > function addOption(formName, selectName, optionText, optionValue, selected,
    > defaultSelected) {
    > var theSelect = document.forms[formName].elements[selectName];
    > theSelect.options[theSelect.length] = new Option(optionText, optionValue,
    > selected, defaultSelected);
    > }
    >
    > In the new window:
    >
    > <CFSET dtkey = "1">
    > <SCRIPT type="text/javascript">
    > function Venue() {
    > if (opener && opener.clearSelect && opener.addOption) {
    > opener.clearSelect('crsadd', 'venue1');
    > opener.addOption('crsadd', 'venue1', 'Select Venue...', '', true);
    >
    > <CFOUTPUT query="venue">
    > <CFIF venuename EQ "na">
    > opener.addOption('crsadd', 'venue1',
    > '#address#-#cityname#,#relprovID#','#venueID#');
    > <CFSET dtkey = #IncrementValue(dtkey)#>
    > <CFELSE>
    > opener.addOption('crsadd', 'venue1',
    > '#venuename#-#address#-#cityname#,#relprovID#','#venueID#');
    > <CFSET dtkey = #IncrementValue(dtkey)#>
    > </CFIF>
    > </CFOUTPUT>
    > }
    > Venue();
    > </SCRIPT>
    >
    > Untested, I think I probably made a mistake somewhere translating what you
    > were doing into the opener callback, but you should have the basic idea. Don't
    > try to manipulate opener directly, call functions in opener that do what you
    > want.
    >
    > Pasquale wrote:
    >
    >
    >>I am using the following code below in a pop-up window to update the
    >>select list in the opening window. Works fine in Netscape 7.02, but I
    >>get a "server threw an exception" error when using it in IE 6.0.2800.
    >>
    >>This code is supposed to avoid the "server threw an exception" error.
    >>
    >>Any suggestions.
    >>
    >><CFSET dtkey = "1">
    >><SCRIPT type="text/javascript">
    >>function Venue() {
    >>opener.document.crsadd.venue1.options.length = 0;
    >>opener.theoption = new Option('Select Venue...','',1);
    >>opener.document.crsadd.venue1[opener.document.crsadd.venue1.length] =
    >>opener.theoption;
    >>
    >> <CFOUTPUT query="venue">
    >> <CFIF venuename EQ "na">
    >>opener.theoption = new Option('#address#-#cityname#,
    >>#relprovID#','#venueID#');
    >>opener.document.crsadd.venue1[opener.document.crsadd.venue1.length] =
    >>opener.theoption;
    >><CFSET dtkey = #IncrementValue(dtkey)#>
    >> <CFELSE>
    >>opener.theoption = new Option('#venuename#-#address#-#cityname#,
    >>#relprovID#','#venueID#');
    >>opener.document.crsadd.venue1[opener.document.crsadd.venue1.length] =
    >>opener.theoption;
    >><CFSET dtkey = #IncrementValue(dtkey)#>
    >> </CFIF>
    >> </CFOUTPUT>
    >>}
    >>Venue();
    >></SCRIPT>
    >>
    >>kaeli wrote:
    >>
    >>>In article <>,
    >>> enlightened us with...
    >>>
    >>>
    >>>>Hello,
    >>>>
    >>>>I wondering if there is a way to dynamically update a select list with
    >>>>javascript from a database query without having to reload the page to
    >>>>update the list?
    >>>>
    >>>>
    >>>
    >>>
    >>>With client-side javascript alone, no.
    >>>With an ActiveX or COM add-in, yes, but the solutions tend to be IE
    >>>only.
    >>>With client-side javascript tag that uses a source of a server-side file
    >>>that outputs javascript, yes.
    >>>
    >>>I'll assume you'd like that last one.
    >>><script type="text/javascript"
    >>>src="http://www.myserver.com/myDirectory/cgi-bin/myCGI.pl"></script>
    >>>
    >>>myCGI.pl would need to output the javascript that updates the select
    >>>with the proper header info that says it's text/javascript.
    >>>There's lots of posts for how to dynamically generate / change select
    >>>boxes, so I'll not post that bit. Google has plenty of hits for the
    >>>topic as well.
    >>>

    >>

    >
    > --
    > | Grant Wagner <>
    >
    > * Client-side Javascript and Netscape 4 DOM Reference available at:
    > *
    > http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html
    >
    > * Internet Explorer DOM Reference available at:
    > *
    > http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp
    >
    > * Netscape 6/7 DOM Reference available at:
    > * http://www.mozilla.org/docs/dom/domref/
    > * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    > * http://www.mozilla.org/docs/web-developer/upgrade_2.html
    >
    >
     
    Pasquale, Jun 16, 2004
    #5
    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. Anonymous
    Replies:
    0
    Views:
    1,531
    Anonymous
    Oct 13, 2005
  2. Pranjal Jain
    Replies:
    3
    Views:
    178
    saras
    Apr 10, 2008
  3. Rase In
    Replies:
    0
    Views:
    118
    Rase In
    Aug 26, 2009
  4. palmiere
    Replies:
    1
    Views:
    450
    Erwin Moller
    Feb 9, 2004
  5. Arjen
    Replies:
    1
    Views:
    147
    Lasse Reichstein Nielsen
    Jun 26, 2004
Loading...

Share This Page