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

Hi All
I am trying to use javascript in my perlCGI version. I would like to bring up a popup box, to check the value entered in one of the textfield when the user clicks the submit button. I have given what I have done so far. What I need to do is either refresh the page/return to the same page when the user clicks cancel in the popupbox and continue with the process when said OK.
sub write_form{ my $additional_html = shift; $additional_html ||=''; print $dw->header({'menu' => 1, 'script' => "function check_name() { var sname; var r; sname = document.main.snp.value; confirm(sname) ; }" }); print $additional_html; print $cgi->br(); print $cgi->h4('Register TaqMan Assay'); print $cgi->br(); print $cgi->start_form({-name =>'main', -method =>'post', -action =>'/cgi-bin/prodsoft/Genotyping/register_taqma +n_new.pl', -onSubmit=>'return check_name()'}); }
Could you drop in any suggestions on i) how could we check the cancel clicked and return the same page or refresh the page? ii) instead of checking when 'clicking the submit' is there any other way to check them before ?
thanks

Replies are listed 'Best First'.
Re: Javascript in CGI header
by Anonymous Monk on Feb 01, 2010 at 13:07 UTC
    header is for HTTP headers, not HTML ... you can find the documentation at CGI and extra examples in the examples directory.
Re: Javascript in CGI header
by ahmad (Hermit) on Feb 01, 2010 at 13:05 UTC

    Apparently no body likes javascript here, And this is more a javascript question than perl.

    Anyway, Your javascript code should look like this

    if ( confirm('are you sure you want to use the name' + sname) ) { return true; }else{ return false; }

    when your javascript function returns false, your form wont be submitted, so you don't need to refresh the page.

    When OK clicked the form will be submitted and you'll have to do the rest through your perl code.

      Apparently no body likes javascript here, And this is more a javascript question than perl

      You know what they say about assumptions?

        Many people, said many things. It depends on what quote you're referring to.