Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Need buttons on web page for retrieving database values

by brysonic venture (Initiate)
on Mar 28, 2000 at 05:10 UTC ( [id://6301]=perlquestion: print w/replies, xml ) Need Help??

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

No not the poodle... I am using a CGI script to access a mysql database. I would like to have buttons at the top that when activated (onClick) will open the database, retrieve the data through a series of SQL statements and return the data to the browser (this is for an internal website). My understanding is that javascript is the best way to do this. Does anyone have any examples of this being used? print p($query->button(-name=>'test', -value=>'test', -onClick=>"?????????")); thx muchly
  • Comment on Need buttons on web page for retrieving database values

Replies are listed 'Best First'.
Re: Need buttons on web page for retrieving database values
by plaid (Chaplain) on Mar 28, 2000 at 06:37 UTC
    You'll have to use normal form submit buttons for this. Javascript buttons that have functions responding to onClick events can execute client-side code only, and can't talk to your database.. a full-fledged submit must be done. If you need 12 different buttons, you'll either need to (as mentioned above) name the submit buttons, or use 12 different forms on your page. I would choose the latter of those two choices, as it would let you break up the code into more managable chunks, rather than one huge block of code which must be re-parsed on every submit and use a bunch of if/elsif statements. This also, of course, depends on if, and how much, of the same code will be executed depending on which button is pressed.
      Just as an aside--the reason I suggested the former is because, for my own purposes, I've wanted to display a row of buttons; and if I put these into separate forms, browsers generally seem to insert paragraph breaks between the forms, which thwarts any attempt at horizontal alignment. That's more of an HTML issue, of course.

      In general, I'd agree w/ you about separating different pieces of functionality; though a general approach I've been taking recently is to have one main script which contains some dispatch code--upon receiving a new request, it determines the nature of the request, then hands it off to the appropriate handler, where each handler is generally stored in its own module.

        I've also run across the big vertical break between submit buttons from different forms on a page. One thing I've done (which is far from optimal, but looks better than the big gap) is to stick the buttons in a table, each in its own <td>. This at least gives the illusion of a row of buttons.

        The approach of having one main script dispatching calls to various handlers sounds like a good one.. I just wanted to make sure and point out the performance benefit of not having to parse 2000 lines of code to then only execute 20. I've seen this done way too many times in beginning CGIs.

Re: Need buttons on web page for retrieving database values
by setantae (Scribe) on Mar 28, 2000 at 05:14 UTC
Re: Need buttons on web page for retrieving database values
by brysonic venture (Initiate) on Mar 28, 2000 at 05:47 UTC
    What I am looking for is how to embed those java acript buttons with in my Perl Script. The design (not by me, Ime just the lackey carrying it out) calls for 12 buttons...I cannot have 12 submit buttons tied to seperate queries can I? thx
      You can if you give them names. For example, in your HTML:
      <input type=submit name=do_connect value="Connect"> <input type=submit name=do_results value="Get Results">
      Then, in your program:
      use CGI; my $query = new CGI; if ($query->param('do_connect')) { # connect to database } elsif ($query->param('do_results')) { # get results of sql call }
      Or something along those lines.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found