The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Drop a Column from a File Raamc UNIX for Dummies Questions & Answers 4 01-09-2008 06:36 AM
Drop records with non-numerics in field X akxeman Shell Programming and Scripting 3 08-14-2007 09:55 PM
Drop down menu in bash for timezone select simonb Shell Programming and Scripting 1 04-29-2006 10:02 AM
Drop Users trfrye UNIX for Dummies Questions & Answers 2 08-31-2005 12:39 PM
text boxes, radio buttons , check boxes in c++ on unix devy8 High Level Programming 3 07-07-2001 02:58 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-12-2007
Registered User
 

Join Date: Apr 2006
Posts: 89
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

Regards,
Garric
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-12-2007
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,422
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.
Reply With Quote
  #3 (permalink)  
Old 10-12-2007
Registered User
 

Join Date: Apr 2006
Posts: 89
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
Reply With Quote
  #4 (permalink)  
Old 10-12-2007
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,422
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
DOM: DOM - MDC
Reply With Quote
  #5 (permalink)  
Old 10-13-2007
Registered User
 

Join Date: Apr 2006
Posts: 89
Thats great !! Thanks for the help. I will read more about that and see if I can solve it.
Reply With Quote
  #6 (permalink)  
Old 10-15-2007
Registered User
 

Join Date: Apr 2006
Posts: 89
Could you give me a small example showing the same?

Regards,
garric
Reply With Quote
  #7 (permalink)  
Old 10-15-2007
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,422
This is the simplest example. Save it as "testdropbox.pl":

Code:
#!/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|
<html>
	<head>
		<title>Dropbox Demo</title>
	</head>
	<body>
		<form action="testdropbox.pl" method="post" id="tst">
		<table><tr><td>
|;
print_cty_dropbox($cgi->param('cty'));
print qq|
		</td><td>
|;
print_city_dropbox($cgi->param('cty'));
print qq|
		</td></tr></table>
		</form>
		<script type="text/javascript"><!--
			document.getElementById('cty').onchange = function() {
				document.getElementById('tst').submit();
			};
		// --></script>
	</body>
</html>
|;
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0