Double combo

G

groupie

Hi,
Trying to create a double-combo, like this example
http://www.javascriptkit.com/script/cut183.shtml ,and here: http://www.cbg.ie/

However the example is using hard-coded values from an array, but I
would like to read the values from a database table.

My first combo (parent) is being populated at the moment in javascript
with an SQL statement and is working fine. When an entry is selected
from the parent, I want to pick up the related items from the database
(tables have been setup) to populate the second (child) combo.

Any ideas how this can be done?

Thanks.
 
E

Erwin Moller

groupie schreef:
Hi,
Trying to create a double-combo, like this example
http://www.javascriptkit.com/script/cut183.shtml ,and here: http://www.cbg.ie/

However the example is using hard-coded values from an array, but I
would like to read the values from a database table.

My first combo (parent) is being populated at the moment in javascript
with an SQL statement and is working fine. When an entry is selected
from the parent, I want to pick up the related items from the database
(tables have been setup) to populate the second (child) combo.

Any ideas how this can be done?

Thanks.

Hi,

2 solutions:
1) You can do this with AJAX
2) or by passing all values for second box into your page immediately
and let Javascript use them to populate your second select, based on the
first option choosen.

If you have a lot of options, your page will get quite long, and AJAX
might be the better approach.

Regards,
Erwin Moller
 
T

Thomas 'PointedEars' Lahn

groupie said:
My first combo (parent) is being populated at the moment in javascript
with an SQL statement and is working fine. When an entry is selected
from the parent, I want to pick up the related items from the database
(tables have been setup) to populate the second (child) combo.

Any ideas how this can be done?

I don't know what you mean by "populated ... in javascript with an SQL
statement". Are you making a request already that causes the server to
issue a SQL query?

If yes:

You only have to trigger a similar server-side resource (can be the same)
and use a similar client-side script that you already do, to populate the
second _`select' element_. Use the `onchange' or `onclick' event handler
attributes to handle the corresponding events (which one is best depends on
your form).

If no:

Use XHR onload or onclick, and have your server generate either a markup
fragment or ECMAScript-compatible code (e.g. JSON) from the SQL query
result; use this to populate the second `select' element.

As fallback, programmatically submit the form or make a GET request to the
generator of the form using the form's serialization (which one is better
depends on your form).

As a fallback for that, include a submit button in a `noscript' element.


HTH

PointedEars
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top