creating dynamic select list from DB query

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

    #1

    creating dynamic select list from DB query

    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?

  • kaeli

    #2
    Re: creating dynamic select list from DB query

    In article <40C53822.10204 03@NOTHNXtelusp lanet.net>,
    spdrweb@NOTHNXt elusplanet.net enlightened us with...[color=blue]
    > 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?
    >
    >[/color]

    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.co m/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.



    Comment

    • Pasquale

      #3
      Re: creating dynamic select list from DB query

      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.theoptio n = new Option('Select Venue...','',1) ;
      opener.document .crsadd.venue1[opener.document .crsadd.venue1. length] =
      opener.theoptio n;

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


      kaeli wrote:[color=blue]
      > In article <40C53822.10204 03@NOTHNXtelusp lanet.net>,
      > spdrweb@NOTHNXt elusplanet.net enlightened us with...
      >[color=green]
      >>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?
      >>
      >>[/color]
      >
      >
      > 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.co m/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.
      >[/color]

      Comment

      • Grant Wagner

        #4
        Re: creating dynamic select list from DB query

        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(for mName, selectName) {
        document.forms[formName].elements[selectName].options.length = 0;
        }
        function addOption(formN ame, selectName, optionText, optionValue, selected,
        defaultSelected ) {
        var theSelect = document.forms[formName].elements[selectName];
        theSelect.optio ns[theSelect.lengt h] = new Option(optionTe xt, optionValue,
        selected, defaultSelected );
        }

        In the new window:

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

        <CFOUTPUT query="venue">
        <CFIF venuename EQ "na">
        opener.addOptio n('crsadd', 'venue1',
        '#address#-#cityname#,#rel provID#','#venu eID#');
        <CFSET dtkey = #IncrementValue (dtkey)#>
        <CFELSE>
        opener.addOptio n('crsadd', 'venue1',
        '#venuename#-#address#-#cityname#,#rel provID#','#venu eID#');
        <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:
        [color=blue]
        > 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.theoptio n = new Option('Select Venue...','',1) ;
        > opener.document .crsadd.venue1[opener.document .crsadd.venue1. length] =
        > opener.theoptio n;
        >
        > <CFOUTPUT query="venue">
        > <CFIF venuename EQ "na">
        > opener.theoptio n = new Option('#addres s#-#cityname#,
        > #relprovID#','# venueID#');
        > opener.document .crsadd.venue1[opener.document .crsadd.venue1. length] =
        > opener.theoptio n;
        > <CFSET dtkey = #IncrementValue (dtkey)#>
        > <CFELSE>
        > opener.theoptio n = new Option('#venuen ame#-#address#-#cityname#,
        > #relprovID#','# venueID#');
        > opener.document .crsadd.venue1[opener.document .crsadd.venue1. length] =
        > opener.theoptio n;
        > <CFSET dtkey = #IncrementValue (dtkey)#>
        > </CFIF>
        > </CFOUTPUT>
        > }
        > Venue();
        > </SCRIPT>
        >
        > kaeli wrote:[color=green]
        > > In article <40C53822.10204 03@NOTHNXtelusp lanet.net>,
        > > spdrweb@NOTHNXt elusplanet.net enlightened us with...
        > >[color=darkred]
        > >>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?
        > >>
        > >>[/color]
        > >
        > >
        > > 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.co m/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.
        > >[/color][/color]

        --
        | Grant Wagner <gwagner@agrico reunited.com>

        * Client-side Javascript and Netscape 4 DOM Reference available at:
        *


        * Internet Explorer DOM Reference available at:
        *
        http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html


        Comment

        • Pasquale

          #5
          Re: creating dynamic select list from DB query

          Thanks Grant. It works beautifully.

          Grant Wagner wrote:[color=blue]
          > 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(for mName, selectName) {
          > document.forms[formName].elements[selectName].options.length = 0;
          > }
          > function addOption(formN ame, selectName, optionText, optionValue, selected,
          > defaultSelected ) {
          > var theSelect = document.forms[formName].elements[selectName];
          > theSelect.optio ns[theSelect.lengt h] = new Option(optionTe xt, optionValue,
          > selected, defaultSelected );
          > }
          >
          > In the new window:
          >
          > <CFSET dtkey = "1">
          > <SCRIPT type="text/javascript">
          > function Venue() {
          > if (opener && opener.clearSel ect && opener.addOptio n) {
          > opener.clearSel ect('crsadd', 'venue1');
          > opener.addOptio n('crsadd', 'venue1', 'Select Venue...', '', true);
          >
          > <CFOUTPUT query="venue">
          > <CFIF venuename EQ "na">
          > opener.addOptio n('crsadd', 'venue1',
          > '#address#-#cityname#,#rel provID#','#venu eID#');
          > <CFSET dtkey = #IncrementValue (dtkey)#>
          > <CFELSE>
          > opener.addOptio n('crsadd', 'venue1',
          > '#venuename#-#address#-#cityname#,#rel provID#','#venu eID#');
          > <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:
          >
          >[color=green]
          >>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.docume nt.crsadd.venue 1.options.lengt h = 0;
          >>opener.theopt ion = new Option('Select Venue...','',1) ;
          >>opener.docume nt.crsadd.venue 1[opener.document .crsadd.venue1. length] =
          >>opener.theopt ion;
          >>
          >> <CFOUTPUT query="venue">
          >> <CFIF venuename EQ "na">
          >>opener.theopt ion = new Option('#addres s#-#cityname#,
          >>#relprovID#', '#venueID#');
          >>opener.docume nt.crsadd.venue 1[opener.document .crsadd.venue1. length] =
          >>opener.theopt ion;
          >><CFSET dtkey = #IncrementValue (dtkey)#>
          >> <CFELSE>
          >>opener.theopt ion = new Option('#venuen ame#-#address#-#cityname#,
          >>#relprovID#', '#venueID#');
          >>opener.docume nt.crsadd.venue 1[opener.document .crsadd.venue1. length] =
          >>opener.theopt ion;
          >><CFSET dtkey = #IncrementValue (dtkey)#>
          >> </CFIF>
          >> </CFOUTPUT>
          >>}
          >>Venue();
          >></SCRIPT>
          >>
          >>kaeli wrote:
          >>[color=darkred]
          >>>In article <40C53822.10204 03@NOTHNXtelusp lanet.net>,
          >>>spdrweb@NOTH NXtelusplanet.n et enlightened us with...
          >>>
          >>>
          >>>>Hello,
          >>>>
          >>>>I wondering if there is a way to dynamically update a select list with
          >>>>javascrip t 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.co m/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.
          >>>[/color]
          >>[/color]
          >
          > --
          > | Grant Wagner <gwagner@agrico reunited.com>
          >
          > * Client-side Javascript and Netscape 4 DOM Reference available at:
          > *
          > http://devedge.netscape.com/library/...ce/frames.html
          >
          > * Internet Explorer DOM Reference available at:
          > *
          > http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html
          >
          >[/color]

          Comment

          Working...