creating dynamic select list from DB query

P

Pasquale

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?
 
K

kaeli

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.

--
 
P

Pasquale

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>
 
G

Grant Wagner

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.
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>
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 <[email protected]>

* 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
 
P

Pasquale

Thanks Grant. It works beautifully.

Grant said:
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>
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 <[email protected]>

* 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top