At 15:43 -0500 20/01/2011, Levan, Jerry wrote:

I basically have a form with a text box, users
can enter sql in the text box and hit the submit
button and the Perl CGI will do its magic on all of
the text in the box.

Query results will appear as html tables.

I would like one more enhancement...

I would like to be able to 'select' some text in
the text box and using possibly a different
submit button have the CGI code only process the
selected text.

My gut feeling is that this might involve using
javascript which is bad since it has been about
Fifteen years since I have written any js code....

I am halfway through doing a very similar thing and found a suitable script on my first attempt.

I append the subroutine I have used to insert the script into the <head> and below it the stuff for the button. At present I have it only inserting the selection into text box "selected_ix" in form "aform" but the routine will be elaborated soon to post the query. I'm sure you can work it out if I can, since I'm practically javascript illiterate.

my $s= qq~
<script type="application/ecmascript" charset="utf-8">
// <![CDATA[
        function getSelText()
                var txt = '';
                 if (window.getSelection)
                        txt = window.getSelection();
                else if (document.getSelection)
                        txt = document.getSelection();
                else if (document.selection)
                        txt = document.selection.createRange().text;
                else return;
        document.aform.selected_ix.value =  txt;
// ]]>
return $s;

<input type="BUTTON" value="Enter selected"
method="post" action="" enctype="multipart/form-data"

Reply via email to