Need one more tweak...

2011-01-20 Thread Levan, Jerry
Hi,

I am almost done with my quest for a way to interact with
a postgresql database with a Perl CGI.

I am trying to find a way to interact with my
database via my iPad and web access seems to be
the key.

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

Can anyone offer any guidance?

What I have now works well and looks good (to me)
on the iPad but I think that being able to select
text to 'execute' will improve the work flow.

Thanks

Jerry






Re: Need one more tweak...

2011-01-20 Thread John Delacour

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()