#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    43
    Rep Power
    7

    Cgi page refresh with parameters


    Hi,

    **UPDATED**

    So I have my url variable working but I can't find how to change the value of a variable on click of a button.

    Any help would be greatly appreciated

    Thanks

    Code:
    #!/bin/perl 
    
    use CGI;
    
    <form action="/perl/script.pl" method="get">
    <input type="text" name="a" value="0">
    <input type="submit" value="Submit">
    my $getvar = CGI->new();
    my $run = $getvar->param('a');
    my $q = CGI->new; 
    
    my $go = $q->param('go');
    
    sub print_html{ #prints html stuff } 
    
    sub one{ #does some stuff runs - no matter what } 
    
    sub two{ #does some other stuff } 
    
    ##MAIN================= 
    print_html; 
    
    $button = qq(<tr><td align=center></td><td><input 
    
    type="Button" name="runsql" value="GO" onclick="?");
    
    print "$button\n"; 
    
    one; 
    
    if( run == 1 ){ two; }
    
    exit;
    Last edited by kochaloch; November 8th, 2012 at 03:52 PM.
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,258
    Rep Power
    1810
    I may be misunderstanding the problem, but if you want to send data back to your script, you would normally use the submit button. The onclick method is typically used to run some javascript, which could in turn submit a request back to your script if you needed to do something complex.

    Comments on this post

    • kochaloch agrees
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    43
    Rep Power
    7
    Ah OK, ya that makes sense. I solved my problem by directing to a splash page on click of the button and runs some code then redirects back to the main page, but I don't like it and think I going to revisit now.

    Thanks for the help!
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    43
    Rep Power
    7

    Updated


    OK, so I have everything working but I need to set the query_string on submit of the button, but when It's clicked it just appends a "?" and not the value im trying to append.

    Any help appreciated

    Code:
    #!c:/Perl/bin/perl.exe
    
    use CGI qw(:all -no_xhtml);
    use CGI::Carp qw(fatalsToBrowser);
    
    sub testhtml
    {
    print <<"EOHC";
    Content-Type: text/html
    
    <HTML>
    	<BODY>
    	<h1 align="center"><b>TEST</h1>
    	<form action="http://localhost/button.pl?2"
          method="GET">
    	<input type="submit" value="Click me">
    </form>
    	</BODY>
    </HTML>
    EOHC
    }
    
    
    sub test{
    
    $success = 'yay';
    print $success
    
    }
    
    testhtml;
    
    if ($ENV{'QUERY_STRING'} eq "2")
        {
    
    test;
    
    }
    Last edited by kochaloch; November 19th, 2012 at 03:39 PM.

IMN logo majestic logo threadwatch logo seochat tools logo