Dynamic Drop down boxes

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 1  
Dynamic Drop down boxes

Hello All,

I am trying to come up with this interface with the backend on perl. The interface needs drop down boxes with dynamic chain loading ( as in contents of the 1st drop down box will populate the second drop down and so on) Any idea how I can do this?

Kindly help

# 2  
Use HTML with a single form element embracing all your drop downs ("select"s). You may need some Javascript to initiate script-triggered form submit when user changes the dropdown selection. As the form submission takes place, it will be received by Web server and the form processor is presumably a CGI script which receives the form parameters, re-generate the HTML to highlight the selected option and present an updated view based on what is selected. This CGI script can be written in Perl and executed from a CGI-enabled Web server.

If you understand HTML form processing and CGI, this should be a pretty straightforward task. Otherwise, please do some reading on this (i.e. HTML forms and Perl CGI scripting), as we cannot cover so much knowledge with such a tiny space here.
# 3  
I understand the HTML and CGI part of it. But how do I integrate the Javascript into this? It will help me if you can lead me to some documentation on the same. Thanks
# 4  
Javascript is just embedded in HTML (or in a separate .js file linked from the HTML, as I normally prefer), so your CGI just output the "script" element like normal plain text with Perl/CGI.

Javascript is the language you write your client-side scripts, but to access the objects on the HTML document (such as form controls) you will need to do so through the Javascript binding of DOM. You will need to set Javascript event handlers to capture selection change event of dropboxes.

Official advise starts here:

Javascript: JavaScript - MDC
# 5  
Thats great !! Thanks for the help. I will read more about that and see if I can solve it.
# 6  
Could you give me a small example showing the same?

# 7  
This is the simplest example. Save it as "testdropbox.pl":

#!/usr/bin/perl -w

use CGI;
my $cgi = CGI->new();
print $cgi->header('text/html');

my %locations = (
	'ca' => {
		'desc' => 'Canada',
		'cities' => {
			'ca_to' => 'Toronto',
			'ca_vc' => 'Vancouver',
	'us' => {
		'desc' => 'United States',
		'cities' => {
			'us_ny' => 'New York',
			'us_sf' => 'San Francisco',

sub print_cty_dropbox {
	my ($cty) = @_;
	print qq|
	<select id="cty" name="cty">
	<option id="--" | . (!$cty?'selected="selected"':'') . qq|>Please choose country</option>|;
	foreach (keys %locations) {
		print qq|<option value="$_" | . (($cty && ($cty eq $_))?'selected="selected"':'') . qq|>${$locations{$_}}{desc}</option>\n|;
	print "</select>\n";

sub print_city_dropbox {
	my ($cty) = @_;
	return if (!$cty);
	print qq|
	<select id="city" name="city">
	<option id="--" selected="selected">Please choose city</option>|;
	foreach (keys %{$locations{$cty}->{'cities'}}) {
		print qq|<option value="$_">| . $locations{$cty}->{'cities'}{$_} .  qq|</option>\n|;
	print "</select>\n";

print qq|
		<title>Dropbox Demo</title>
		<form action="testdropbox.pl" method="post" id="tst">
print qq|
print qq|
		<script type="text/javascript"><!--
			document.getElementById('cty').onchange = function() {
		// --></script>

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #489
Difficulty: Medium
Because interpreted languages are not compiled, syntax errors do not become runtime errors.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

DNS Drop out

My boss use a MacBook and he encounter with DNS drop out and he cannot surf website for 1-2 mins. The DNS Service of my company is on UNIX server. I try to delete some unused IP of DNS Server in resolv.conf and dhcp.conf and I try to update root.hint file but The problem is not fixed. Please... (5 Replies)
Discussion started by: thsecmaniac
5 Replies

2. Web Development

Dynamic Drop Down Menu

I need to create a dynamic drop down menu which is populated by entries such as; htdocs/client1/index.php htdocs/client2/index.php htdocs/client3/index.php htdocs/client4/index.php etc. So htdocs/client*/index.php Is this possible? I know how to do this using normal arrays, but not... (2 Replies)
Discussion started by: JayC89
2 Replies

3. UNIX for Advanced & Expert Users

Sql dynamic table / dynamic inserts

I have a file that reads File (X.txt) Contents of record 1: rdrDESTINATION_ADDRESS (String) "91 971502573813" rdrDESTINATION_IMSI (String) "000000000000000" rdrORIGINATING_ADDRESS (String) "d0 movies" rdrORIGINATING_IMSI (String) "000000000000000" rdrTRAFFIC_EVENT_TIME... (0 Replies)
Discussion started by: magedfawzy
0 Replies

4. Shell Programming and Scripting

Drop down menu

How to create a drop down menu in either bash or ksh? (3 Replies)
Discussion started by: proactiveaditya
3 Replies

5. Shell Programming and Scripting

drop down structure in file

I have file like this 120, rahim, d40 115, rahul, d40 113, begum, d40 I want to group this file like this 120, rahim, d40 115, rahul, 113, begum, can any one help me on this thanks in advance (1 Reply)
Discussion started by: trichyselva
1 Replies

6. Shell Programming and Scripting

using sed but want to drop last line

Howdy all. I have some scripts that read a text file looking for a keyword, then returning all the text until another keyword and puts it into a new file. Problem is, sed returns the entire last line that contains the 2nd keyword, and I don't want it! Here's an example of the sed script line: ... (21 Replies)
Discussion started by: atc98092
21 Replies

7. UNIX for Dummies Questions & Answers

Drop a Column from a File

Hi, I need to drop a column from a file. My .txt file having 20 columns first column as GroupBy column which is not necessery in further processing. So i need to create a new files without this column. Please help how to do this? Thanks, Raamc :rolleyes: (4 Replies)
Discussion started by: Raamc
4 Replies

8. UNIX for Dummies Questions & Answers

Drop Users

I know that this is a really simple and stupid question, but how do I drop / disconnect a user who is logged in? AIX 5.2 (2 Replies)
Discussion started by: trfrye
2 Replies

9. Programming

text boxes, radio buttons , check boxes in c++ on unix

Hi ! Please tell me how to get radio buttons, text boxes , check boxes , option buttons , pull down menus in C++ on Unix. I think it would be done using curses.h ..but that's all i know. TIA, Devyani. (3 Replies)
Discussion started by: devy8
3 Replies

Featured Tech Videos