Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Executing a function on submit

by CyCliC (Novice)
on Jul 30, 2001 at 11:58 UTC ( [id://100809]=perlquestion: print w/replies, xml ) Need Help??

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

my code looks something like this

print header( "text/html" ); print start_html(-title => "Bookshelf at Reddo Networks", -bgcolor => "#ffffff" ); print start_form(); print p("Document nr: ", textfield("doc_nr")); print p("Document name: ", textfield("doc_name")); print p("Author: ", popup_menu("author", \@authors)); print p(submit("DO"), reset("clear")); print end_form(), hr(); print_content(); print end_html; write_content(); sub print_content { open(DAT, "<doc_number.dat"); @all = <DAT>; foreach $b (@all){ print p($b); } close(DAT); } sub write_content { print p("tada"); }
how do I run the write_content function when the submit button has been pressed

Replies are listed 'Best First'.
Re: Executing a function on submit
by tadman (Prior) on Jul 30, 2001 at 14:44 UTC
    You can't send the script to the client, unless you can do this all in JavaScript, which in your trivial example you probably can.

    If you're doing something more ambitious, you will have to use a separate script, or one that has a "trigger" in it. Something like:
    my $cgi = new CGI; # Your old stuff # : print end_form(), hr(); print_content(); print_end_html(); if ($cgi->param('DO')) { write_content(); }
    Make sure that the ACTION parameter of the form is set to itself, which it should be if you don't give it any parameters. When you click on the "DO" button, it should send a DO parameter to the server with the value of the button.
Re: Executing a function on submit
by voyager (Friar) on Jul 30, 2001 at 18:58 UTC
    Javascript in the browser is the answer. There are a number of ways, but probably you want an onClick event on the button that does something like document.write("tada")

    Note: there are several ways to detect events that can trigger Javascript, and there are a mulititude of ways to get content written to the browser. Now, if you want to get cross-browser compliant, it gets trickier.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-26 03:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found