Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
No such thing as a small change
 
PerlMonks  

Assigning a value from JavaScript onSubmit in CGI

by rashley (Scribe)
on Nov 16, 2006 at 12:46 UTC ( [id://584534]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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

I have a CGI that's creating a button.

I know I can use -onsubmit to call a JavaScript to go and do something.

Can I call a JavaScript that returns a value, and assign that value?

For instance:

my button = button(-name=>'Name', -value=>'Value', -onclick=>"return dosomtehing()", -onsubmit=>$Hash->{VALUE}="return getsomething()");

The syntax above for that last line doesn't work. Can this even be done? Thanks.

Replies are listed 'Best First'.
Re: Assigning a value from JavaScript onSubmit in CGI
by Anonymous Monk on Nov 16, 2006 at 12:52 UTC

    JavaScript running on the browser cannot set a variable in a program that's no longer running on the server. You'll have to take a different approach.

      I was afraid of that. Thanks.
Re: Assigning a value from JavaScript onSubmit in CGI
by BaldPenguin (Friar) on Nov 16, 2006 at 12:57 UTC
    Difficult, to my understanding, onsubmit is only valid in the 'form' tag, in fact the button press will not trigger a submit method at all. What is the actual flow you are looking for here?

    Don
    WHITEPAGES.COM | INC
    Everything I've learned in life can be summed up in a small perl script!
      Well, I put a Perl function call in the -onsubmit of this button and it got called.

      I have an array reference. When my page gets created the CGI loops through the array and puts the values into Text boxes so they can be changed.

      I have a JavaScript to dynamically add rows to this table.

      When the form is submitted, I need to gather the current values and put them back in my array ref. Here's the code:

      sub generateFlgNotes { my $cgi = shift; my $readonly = shift; my $attr = shift; my $attrHash = shift; my $value = $attrHash->{VALUE}; my $result; $result .= $cgi->start_table({-id=>'FlagNotesTable'}); foreach my $note (@$value) { $result .= $cgi->Tr({}, $cgi->td("<TextArea>$note</TextArea>")); } $result .= $cgi->end_table({}); my $addbutton = button(-name=>'AddFlagNote', -value=>'Add Flag Note', -onclick=>"return addNote('FlagNotesTable', '')", -onsubmit=>?????); $result .= $addbutton; return $result; }
Re: Assigning a value from JavaScript onSubmit in CGI
by rashley (Scribe) on Nov 16, 2006 at 14:48 UTC
    What about putting them into a param, like this?

    my $addbutton = button(-name=>'AddFlagNote', -value=>'Add Flag Note', -onclick=>"return addNote('FlagNotesTable', '')", -onsubmit=>print $cgi->hidden(-name=>'flagNotes', -default =>"return getAllNoteValues('FlagNotesTable')"));

    Any reason why this approach wouldn't work?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://584534]
Approved by Corion
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.