Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

refresh page with values 1

Status
Not open for further replies.

tsp120

Programmer
May 21, 2003
52
0
0
US
I really am not sure where to post this. I have a perl script with CGI, HTML and Javascript. The page contains a form with a lot of radio buttons, select boxes and text fields. It reads data for the radio buttons and select boxes from a mysql database.

There is one set of radio buttons (with two options) and 2 select boxes in particular who's data depends on the selected info in the others. Depending on what is currently selected among the radio buttons and select boxes, the other boxes should only display certain information. All of this comes from one table in the database. The data I am actually working with is very abstract and won't make sense to you, so I'll give a simple example to explain this further.

Let's say I have a table with the following columns:

Day - Meal - Food

Some sample information in this might be:

Saturday - Breakfast - Eggs
Saturday - Breakfast - Ham
Saturday - Lunch - Ham
Saturday - Lunch - Sandwich
Saturday - Lunch - Hot Dogs
Saturday - Dinner - Ham
Saturday - Dinner - Steak
Saturday - Dinner - Hamburgers
Saturday - Dinner - Hot Dogs
Sunday - Breakfast - Eggs
Sunday - Breakfast - Ham
Sunday - Breakfast - Omlette
Sunday - Lunch - Ham
Sunday - Lunch - Sandwich
Sunday - Lunch - Hamburgers
Sunday - Lunch - Hot Dogs

Sorry for the odd example. :)

So if someone clicks the Saturday radio button, the meal select box should contain 'Breakfast', 'Lunch', and 'Dinner'. However, if someone selects the Sunday radio button, the meal select box should contain 'Breakfast', 'Lunch'.

If someone selects Sunday and Lunch, the food select box should contain 'Ham', 'Sandwich', 'Hamburgers', 'Hot Dogs'.

If someone selects 'Steak' from the food list, the meal select box should only contain 'Dinner' and only the 'Saturday' radio button should be available.



I hope all of that made sense. I know how to add or remove information from select boxes and I know how to disable radio buttons using javascript. However, all of this information will need to come from the server side. Therefore I do not believe it is possible to take perl/cgi variables and use them in the javascript.

This leads me to believe that I need to refresh the page upon each selection. Then I can run an sql statement in perl/cgi to populate each select box based on the variables passed in the refresh. If this is what I need to do, I could use some direction on how to get started.

If you have any other suggestions or recommendations, please let me know, or if you think this post would be more suitable for a different board, please let me know.
 
You can use perl variables in javascript, but only when the javascript code is first being written to the browser. If the initial data isn't too freaking much, you can load it all at once into a javascript function and then use javascript from the browser to do all the selecting/filtering to arrive at the final selections the user has to make before sending a request back to the server.
 
Thank you. This sounds like a good way to do it.

Now I will ask, how can I select all info from that table and store it in javascript arrays? (I assume that's what you are recommending).

Thanks again!
 
I am sorry, but mysql is something I am weak at still. But if you already know how to get your mysql data, and you know javascripting, you should be able to figure it out. Just plugin the corresponding perl variables into javascript code that will be used to create the dynamic forms/menues during html generation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top