Re: Need one more tweak...

[email protected] (John Delacour)
Newsgroups perl.macosx
Message-ID <p06240814c95e58059919@[192.168.1.66]>
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.

sub SCRIPT_GET_SELECTED_TEXT{
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;
	}
// ]]>
</script>
~;
return $s;
}



<input type="BUTTON" value="Enter selected"
method="post" action="icsql.pl" enctype="multipart/form-data"
onmousedown="getSelText()">
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.