PDA

View Full Version : Using OnChange Event in Selects


IceManJoe
12-28-2002, 03:55 PM
Hi,

This concerns javascript and ASP so I hope its ok being posted here.

I have 2 tables in a database, tblFruit and tblFruitType

tblFruit has FruitID and FruitDescription
tblFruitType has FruitTypeID, FruitID and FruitTypeDescription

So for example, FruitID 1 could have a FruitDescription of 'Apple' and FruitTypeID 1 could have a FruitTypeDescription of 'Granny Smith' with the FruitID equal to 1.

Basically I have a search form, with 2 dropdown selects on. In the first dropdown it shows all the FruitDescriptions in the database with the option value as FruitID. When a user has selected a fruit description i would like the second dropdown to contain FruitTypeDescriptions for only those with the same FruitID.

I've seen this done before but i'm unsure how to implement. Has anyone done this before and would like to show me whats the best way?

Thanks

piglet
12-28-2002, 08:42 PM
Hi Joe,

There's an example on this thread (http://www.webxpertz.net/forums/showthread.php3?s=&threadid=21268).

IceManJoe
12-29-2002, 11:16 AM
Hi Piglet,

Thanks for the reply, I can see how its done by putting the values in an array. Do you know how it can be done taking the values out of a table in a database (See first post)?

Thanks

Joe

whammy
12-29-2002, 05:04 PM
In order to do that, you'll need to first populate your javascript array with all possible corresponding values from the database.

javabeginner
09-18-2004, 08:33 PM
In order to do that, you'll need to first populate your javascript array with all possible corresponding values from the database.Hi, is "populating array first" the only way to do so? Can I use java script to access the database and populate the combo box directly. Thank. (Hoping knowledgeable folks can see and reply, :confused:

whammy
09-18-2004, 08:46 PM
JavaScript cannot access the database directly, you'll need to post to the server to get database info.

javabeginner
09-18-2004, 09:20 PM
JavaScript cannot access the database directly, you'll need to post to the server to get database info.
Thx..buddy. I am stuck on this for a coulpe days already. I have the same though but I also found two threads showing using java script to connect and to access database. That's why I'm so confused. If don't mind, can you have a look to "How to add rows to a table ?" by sartec. Also the following is another one I found from somewhere else, would it worK?

<SCRIPT LANGUAGE=JAVASCRIPT>
<!--
var conn = new ActiveXObject("ADODB.Connection") ;
var connectionstring = "Provider=sqloledb; Data Source=itdev; Initial Catalog=pubs; User ID=sa;Password=yourpassword"
conn.Open(connectionstring)
var rs = new ActiveXObject("ADODB.Recordset")
rs.Open("SELECT gif, description, page, location FROM menu1", conn)
// Be aware that I am selecting from thi
// s table, but you need to pick your own t
// able
while(!rs.eof)


{
alert(rs(0));
rs.movenext
}

rs.close
conn.close

//-->
</SCRIPT>