Solved

ASP-Javascript array help needed.

Posted on 2002-05-30
11
298 Views
Last Modified: 2006-11-17
I'm writing a travel expense calculator for our budget group.  I've a database of locations linked to counties linked to continents.  I would like to load the three tables into arrays for use by three drop-down select boxes in a form.  Choosing a continent would load the next drop-down box with countries, from which when a country is chosen those country’s locations are available in the third drop-down box, which is the actual field that is required for the travel calculator.  Right now it works but as a continent or country is chosen upon submission the ASP page reloads itself, loading the requested country or location choices.  I would like to do this without reloading the page, I imagine using javascript.  

Note: I got this to work with hard-coded arrays, I want to be able to call a database and have the code load an array for each drop-down box, without reloading the page.

If there is an article, book, web link discussing loading database info into a ASP, Javascript array(s) for use with drop-downs I would appreciate it.

Thanks Don L.
0
Comment
Question by:lauciricad
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7045423
You can't go to the database without reloading the page.  What you can do is use a hidden frame and reload that. Then generate the code for the select after the data is received back from the database.  

However you may have performance problems with this for user with a slow connection. You might want to preload the data into the hidden frame unless it is a really huge amount of data.
 
Cd&
0
 

Author Comment

by:lauciricad
ID: 7045429
I was hoping to load the three tables (Continents, Counties & Locations) at the start, and then use javascript to rebuild the drop-down boxes based on either what continent or country was chosen.  - Therefore not requiring either a call the the database or reload of the page.
0
 

Author Comment

by:lauciricad
ID: 7045456
I was hoping to load the three tables (Continents, Counties & Locations) at the start, and then use javascript to rebuild the drop-down boxes based on either what continent or country was chosen.  - Therefore not requiring either a call the the database or reload of the page.
0
 
LVL 19

Expert Comment

by:webwoman
ID: 7045457
Then you're going to have to load EVERYTHING with that first call to the database. Every possible option will need to be in a javascript array of some kind if you want to do it client side.

You COULD use frames for this -- while you'd still make the calls to the database, each would only load ONE page and a limited amount of data. And you changing your mind would be fast, because the first set of choices would never have to change. Selecting one would load the second frame and reset the third (which could be a straight HTML page). Selecting something from the second would change the third only. It would be flexible because you could pick and choose pretty easily. Keep the first choice, change the second a dozen times -- while it would be a call back to the database, it would be reloading only one small page (most likely only text) with a limited amount of data.  

The user wouldn't necessarily see what was going on. They could only bookmark the main frameset, which would probably be helpful. YOu could carry over values from the other frames and have the last frame load up a submit button, so you could send the info on to something else.

If you've got tons of data to include in that javascript array, this might be the way to go.
0
 

Author Comment

by:lauciricad
ID: 7045574
I would like to use this function on which builds a drop-down with a list from array (Secondlist) matched from what was chosen form list1.  The problem I am having is getting a ASP called database or a hard coded array integrated into the javascript. ** How do you incorporate ASP (VBscript SQL calls) into javascript - or how/can make calls on a database using javascript?

function setList(f) {
 secondlist=eval(f.list1.options[f.list1.selectedIndex].value);
 f.list2.options.length=0;
 for(i=0;i<secondlist.length;i++) {
  f.list2.options[i]=new Option(secondlist[i]);
 };
  f.list2.selectedIndex=0;
};
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:lauciricad
ID: 7045575
The frames option I understand.  I have been trying to avoid using frames.

Don L.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7045607
Client side JavaScript cannot make database calls.  It can only access the data that is on the page at load time. If you have to go back to the database, you have to go to a server side script and you get a reload.  

An HTML page does not hold an open pipe, so every call back to the server results in a reload of some sort.

You may be possible with some kind of activeX control to do the data transfer seamlessly, but you cannot access the database with a JavaScript function on the page.

Cd&
0
 
LVL 18

Expert Comment

by:bruno
ID: 7046216
Like WW said, you have to load everything at once, then just use javascript to pull the correct array and display it as a select.


BRUNO
0
 
LVL 19

Accepted Solution

by:
webwoman earned 100 total points
ID: 7046243
I try to avoid frames too, but in some cases they DO make sense. This is one of those cases.

Why load a huge javascript array of every conceivable combination when it's not necessary? Why reload everything when the user just wants to change one option?
0
 

Author Comment

by:lauciricad
ID: 7047038
Got it. You've both answered what I was coming to realize over the last week or so. - Calling and loading large tables into memory is a method, but slows and sometimes binds-up the client as it resorts the loaded data rebuilding drop-downs on the page.  I've avoided/eliminated using frames as I've learned other methods but agree this is certainly the easier method if not the most efficient.

Both of you have either directly or indirectly provided me great insight.  I'm giving 'webwoman' the points.  Bruno, I'll post another 100 pts for you.

Finally, I'm still interested in Javascript database methods.  I've got the O'reilly "Javascript" definitive guide.  Are there any other books, articles, web sites that have info on the subject.

Thanks

Don L.
0
 
LVL 19

Expert Comment

by:webwoman
ID: 7047615
A lot depends on how many items you have to deal with -- if it's thousands and thousands of pieces of data and complex javascript arrays, it's going to take forever on the client. The server won't get hit, but given that the server normally is much more robust than most client machines would be, going back to the server can be faster than rerendering the entire page every time they want to see a new option.

But for smaller amounts of data and overloaded/limited servers, doing the rerendering client side takes a load off the server.

Like always, there's more than one way to do everything... Thanks for the A!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now