Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

dynamic combo box

by Appy16 (Sexton)
on May 05, 2010 at 07:53 UTC ( #838458=perlquestion: print w/replies, xml ) Need Help??

Appy16 has asked for the wisdom of the Perl Monks concerning the following question:

I have a drop down list which is currently hard coded with a few options.But i want to populate it through a text file.

E.g. Here the options in my code are Image, Fimage and other and i want to populate it through a text file.

I would like to know whether dynamically populating a combo box through a text file is possible or not, because i have been stuck at this point for some time.

I am posting my script below

#!/usr/bin/perl -w use CGI::Ajax; use CGI; sub Show_HTML { my $html = <<EOT; <HTML> <HEAD><title>Dynamic combo box</title> </HEAD> <BODY> <script type="text/javascript"> function CheckIsNumeric() { var AsciiCode = event.keyCode; if ((AsciiCode < 48) || (AsciiCode > 57)) { alert('Please enter only numbers.'); event.cancelBubble = true; event.returnValue = false; } } function display(selector,inputID) { var selector=document.getElementById(selector); var inputID=document.getElementById(inputID); if (selector[selector.selectedIndex].value=="Other") { "block"; } else {"none"; } } </script> <form name="orderform" method="GET" > <input type="radio" name="pick" value="fun1" checked="checked">Func1 &nbsp; &nbsp; <input type="radio" name="pick" value="Fun2" />Func2<br /> <br> Enter a number : &nbsp; &nbsp; <input type="text" name="Number" id="myText" size="6" onkeypress = +"CheckIsNumeric()"/> <br> <br> Enter a value : <select name="Function1" id="f1" STYLE="width: 150px" onchange="re +turn display('f1','b1');"> <option value="image">Image</option> <option value="fimage">fImage</option> <option value="Other">other, please specify:</option> </select> <input type="text" name="box1" id="b1" size="25" style="display: n +one;"> <br> <br> Enter val2 : &nbsp; &nbsp; &nbsp; <input type="text" name="box2" id="b2" size="40"> <br> <br> <input type="submit" value=" Submit " /> </Form> <form name = "Log file" method = "POST" Action="http://localhost/~Ab +c/log.txt"> Click Here to View the Log file : <input type="submit" value="Log File" /> <br> <br> <hr> <br> </Form> </BODY> </HTML> EOT return $html; } my $cgi = new CGI(); my $pjx = new CGI::Ajax( 'functions' => \&functions ); print $pjx->build_html($cgi,\&Show_HTML); $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "GET") { &functions(); } else {} sub functions { print "Radio Button's Value is : " . $cgi->url_param('pick'); print "<br>"; print "Number's Value is : " . $cgi->url_param('Number'); print "<br>"; print "box1's Value is : " . $cgi->url_param('b1'); print "<br>"; print "box2's Value is : " . $cgi->url_param('b2'); print "<br>"; print "<br>"; my $number = $cgi->url_param('Number'); my $g1 = $cgi->url_param('b1'); my $g2 = $cgi->url_param('b2'); if ($number eq "" || $g2 eq "") { print "Please enter all the values"; } else { print "Thank You"; } }

Kindly Help. Thanx in advance.

Replies are listed 'Best First'.
Re: dynamic combo box
by wfsp (Abbot) on May 05, 2010 at 08:45 UTC
    dynamically populating a combo box through a text file
    One way,
    #! /usr/bin/perl use strict; use warnings; use HTML::Template; my $options_file = q{options.txt}; open my $fh, q{<}, $options_file or die qq{cant open *$options_file* to read: $!}; my @options = <$fh>; chomp @options; my @sel; for my $option (@options){ my ($value, $text) = split(q{ }, $option, 2); push @sel, {value => $value, text => $text}; } my $t = HTML::Template->new(filename => q{template.html}); $t->param(loop => \@sel); print $t->output;
    Image image Fimage fimage other other, please specify
    <!-- cut down version --> <select name="Function1" id="f1"> <TMPL_LOOP loop> <option value="<TMPL_VAR value>"><TMPL_VAR text></option> </TMPL_LOOP> </select>

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://838458]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2023-05-30 02:09 GMT
Find Nodes?
    Voting Booth?

    No recent polls found