Sunday, July 17, 2011

How to Creating an active drop-down list using CGI

So you have to make a JavaScript drop-down list of options on your Web page to navigate your site. What about visitors without Javascript-browser? If you no other way to have to get your site, your visitors without JavaScript can result in a loss.

Here's how to handle the above problem with a server-side CGI script to the drop-down list, instead of solving client-side JavaScript. They wonder why someone would take care of even with a JavaScript solution, when a CGI solution to accommodate others? Now, install unfortunately most internet provider is not new CGI scripts into free space, they offer. The other reason is, even if you have CGI access, installing CGI scripts requires experience and patience, if you've never been a CGI script before installing.

First, look for the CGI script itself. We use the Perl language to the CGI script to write because it is the most common server scripting language for web servers. Do not forget to adapt the following script file extension "*. txt" from the "*. pl" or "*. cgi" on your web server needs. Since there is no standard instructions that operate on any web server when you install CGI scripts in Perl, we are not here at this time. Your internet provider must be able to let you know if you have CGI access and to specific instructions on your web server.


#!/usr/bin/perl

sub xcgi_InitForm
{
  my($h) = '[a-fA-F0-9]';
  my($buff, @params, $param);
  my($param_name, $param_value);
  local(*xcgi_form) = @_ if @_;

  read(STDIN, $buff, $ENV{'CONTENT_LENGTH'});

  @params = split(/&/, $buff);

  foreach $param (@params)
  {
    ($param_name, $param_value) = split(/=/, $param);

    $param_value =~ tr/+/ /;
    $param_value =~ s/%($h$h)/pack("C",hex($1))/eg;

    $xcgi_form{$param_name} = $param_value;
  }
}

{
  my(@form);

  xcgi_InitForm(*form);

  $url = $form{'url'};
  print "Location: $urlnn";
}
Listing #1 : PERL code. Download redir.pl (0.44 KB).
Once you get the above CGI script installed on your server, let's say under "/cgi-bin/redir.pl" on your server, simply create an HTML form with a dorp-down list named "url" as follows:
<form method="POST" action="/cgi-bin/redir.pl">

<SELECT NAME="url">
<OPTION VALUE="http://www.chami.com/tips/">
Select a page to visit and click GO</OPTION>

<OPTION VALUE="http://www.chami.com/tips/html/">
HTML Tips</OPTION>

<OPTION VALUE="http://www.chami.com/tips/windows/">
Windows Tips</OPTION>

</SELECT>

<input type="SUBMIT" value="GO">
</form>
Listing #2 : HTML code. Download dropdown.html (0.35 KB).
Your drop-down list choices should be listed in-between <SELECT ...> and </SELECT> tags. The URL for the choice should be listed under the VALUE attribute and the display name of the choice should be in-between <OPTION ...> and </OPTION> tags. For example, to add a choice named "Chami.com home page" with the web page address "http://www.chami.com/" add the following tags to the above form.
<OPTION VALUE="http://www.chami.com/">
Chami.com home page</OPTION>
Listing #3 : HTML code. Download option.html (0.2 KB).

0 comments:

 
Fashion Trend © 2011 | All Rights Reserved | About | Privacy Policy | Contact | Sitemap