473,414 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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?

Jul 23 '05 #1
4 4614
In article <40**************@NOTHNXtelusplanet.net>,
sp*****@NOTHNXtelusplanet.net 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

Jul 23 '05 #2
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 <40**************@NOTHNXtelusplanet.net>,
sp*****@NOTHNXtelusplanet.net 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.


Jul 23 '05 #3
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 <40**************@NOTHNXtelusplanet.net>,
sp*****@NOTHNXtelusplanet.net 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 <gw*****@agricoreunited.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
Jul 23 '05 #4
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 <40**************@NOTHNXtelusplanet.net>,
sp*****@NOTHNXtelusplanet.net 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 <gw*****@agricoreunited.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


Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the...
1
by: Arjen | last post by:
IE 6 does not return the value of a dynamic option list. Mozilla performs fine. How can I get the value of a choice in IE? Simple example below. Option list is filled with first element of array...
3
by: Craig Jurney | last post by:
Am having difficulty creating a dynamic <select> element using direct assignment to the element's option array (ie. someElement.option=new Option(someText, someValue);) that will work on Palm...
2
by: Zlatko Matić | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
1
by: mike | last post by:
I have a select list defined like: <select name="cri2" multiple style="height:220px; width:300px;" onClick="show_content(this);"> </select> I add content to it dynamically using a function...
8
shane3341436
by: shane3341436 | last post by:
I heard that ajax is very powerful for creating dynamic web pages. Is there any way to create a dynamic select field. Like I have two select fields and take data from the database. When choosing a...
2
by: Kirkingly | last post by:
I want to create the following print_r results into a dynamic select list.. I have tried something like: <?php $prefixes = array(explode("\n", $board)); echo '<select name="tprefix">';...
14
by: Heggr | last post by:
I have a page that when you click on a button it is supposed to add 5 more rows to an existing table. This functionality works but then we had to change one of the cells from using a Text box to...
1
by: jmartmem | last post by:
Greetings, I have a nagging problem with client-side dynamic dependent list boxes that perhaps someone can help me troubleshoot. I have a form with a series of dynamic dependent list boxes....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.