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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: JavaScript & Perl
by chromatic (Archbishop) on Jul 24, 2000 at 22:33 UTC
    I'm no JavaScript expert (as jlp will point out), but I thought it was document.location = "foo".

    GET requests are typically passed in the URL string. Look at the URL window right now and see something like ?node_id=24135. You could just append something like "?$name=$value" to your query string for the redirection, but watch out for quoting issues.

    Personally, I'd handle it all in the CGI script:

    use CGI; my $q = CGI->new(); my $rbutton = $q->query('fred'); if ($rbutton eq 'is a loser') { fred_is_a_loser($q); } elsif ($rbutton eq 'is a hero') { fred_is_a_hero($q); } else { # who is fred? # or someone edited HTML locally default($q); }
    The subroutines, of course, would do whatever your specific other scripts do.
      I'm no JavaScript expert (as jlp will point out), but I thought it was document.location = "foo".

      Actually, it's:
      location.href = "http://someplace.com";
      Meaning that's what seems to work for me (whereas location won't under netscape :)
      location is merely an implicit way of stating document.location.

      -- ar0n

Re: JavaScript & Perl
by le (Friar) on Jul 24, 2000 at 23:06 UTC
    Some things come to my mind:

    I don't like JavaScript, and in this case, it is not even necessary. Your clients could alter the JavaScript code, and what happens then to your input processing? Things like these should be left to the server, because of error checking, a.s.o.

    Well, why don't you just write ONE perl script, where you decide via if(){..} else {..} what do to with the user input depending on the checked values? That would be a) safer and b) the perl way.
Re: JavaScript & Perl
by maverick (Curate) on Jul 24, 2000 at 22:31 UTC
    it has been a while since I worked in javascript so this may not be 100% correct...
    function redirect() { if (document.fred.ID[0].checked) { document.fred.action = "doneN.pl"; return true; } else if (document.fred.ID[1].checked) { document.fred.action = "doneP.pl"; return true; } return false; }
    and then
    <form name="fred" onSubmit="redirect()">
    so, the function redirect gets called when the submit button is triggered, and the action element of the form is re-written depending on the radio button. I seem to remember that if the onSubmit returns true, the form submits; false and it doesn't. Some browsers will let you pick none of a set of radio buttons, and this code would catch that.

    But of course this is all browser dependant too.

    If you want to avoid javascript all together (which is usually a good idea). Have the from submit to one of the scripts outright, then check the status of the radio buttons within that script and if the other one was checked, return a redirect to the other script.

    Hope this helps...
    /\/\averick

Re: JavaScript & Perl
by qi3ber (Scribe) on Jul 24, 2000 at 22:53 UTC
    In response to your query as to whether or not perl will allow you to check the results of your form before submittal, no it will not. Unlike JavaScript which is a client side programming language, in which you can instruct the client to verify the contents of a form before submitting it, perl is restricted to server-side processing. This means that perl can only verify the contents of your form after it has been submitted.
      This is not entirely true. In your HTML output you can embed PerlScript which is a perl client side scripting lang. You can use the PerlScript to verify and send it to the server side script.

      --BigJoe
        Which browsers support this PerlScript, as I haven't heard of any and would gladly run any browser which does.
Re: JavaScript & Perl
by Kiko (Scribe) on Jul 24, 2000 at 22:27 UTC
    Why is everyone giving me a negative reputation, on this write up? This question or write up is all about Perl not JavaScript. This one function that i wrote in JS is the only function in my script that contains JS. Let me re-phrase the question. I have a function in JS within my Perl script that doesn't work. Is there a way that i can do this in Perl? Can someone reply back and tell me why i got no response, and instead i got some negative reputations.
      Your question is all about JavaScript, not Perl.