JavaScript function saveText() needs to Update the Perl array@BO_FO_EMAIL

W

William

My first time posting to clj , I have already read
http://jibbering.com/faq/#FAQ2_3 before posting.

javascript function in question:

saveText() is as follows:

function saveText( scroll_list, t_area, listToBeUpdated ) {
alert( listToBeUpdated.name );
// need to know which list to add the value in textarea back into
for(var i = 0; i < scroll_list.options.length; i++) {
if( scroll_list.options.selected == true ) {
scroll_list.options.text = t_area.value;
break;
}
}
// push new value to the corresponding scrolling_list
// then use this scrolling_list to update the dummylist
if ( listToBeUpdated.name == "bo_fo_emails" ) {
// push ( \@BO_FO_EMAILS, t_area.value );
}
}

The webpage is produced with the following Perl code:


print $query->td(
$query->textarea(-name=>'BOFOEmails',
-onChange=>"saveText( this.form.bo_fo_emails,
this.form.BOFOEmails,
this.form.bo_fo_emails )"),
$query->p,
$query->button(-name=>'ADD',
-value=>'Confirm Modifications',
-onClick=>"move(index, this.form.BOFOEmails,
this.form.bo_fo_emails)"),
$query->button(-name=>'REMOVE',
-value=>'Edit Selected Entry',
-onClick=>"edit( this.form.bo_fo_emails,
this.form.BOFOEmails)"));

Basically, I am trying to remove scroll_list.options.text from
@BO_FO_EMAILS and replace it with t_area.value.

Order of elements does matter in BO_FO_EMails. ie.
scroll_list.options.text must be in the same relative position as
t_area.value in @BO_FO_EMAILS.


Problem:
push ( \@BO_FO_EMAILS, t_area.value );

gives a javascript error "Error on Page". How do I update @BO_FO_EMAILS
within the javascript function saveText()?
 
L

Lee

William said:
My first time posting to clj , I have already read
http://jibbering.com/faq/#FAQ2_3 before posting.

javascript function in question:

saveText() is as follows:

function saveText( scroll_list, t_area, listToBeUpdated ) {
alert( listToBeUpdated.name );
// need to know which list to add the value in textarea back into
for(var i = 0; i < scroll_list.options.length; i++) {
if( scroll_list.options.selected == true ) {
scroll_list.options.text = t_area.value;
break;
}
}
// push new value to the corresponding scrolling_list
// then use this scrolling_list to update the dummylist
if ( listToBeUpdated.name == "bo_fo_emails" ) {
// push ( \@BO_FO_EMAILS, t_area.value );
}
}


1. There is never any reason to compare a boolean expression to true.
The value of the comparison expression will always be exactly the
same as the value of the original expression.

if (scroll_list.options.selected) {

2. If you just want the index of the selected item in a Select
object that doesn't allow multiple selections, use its
selectedIndex attribute:

scroll_list.options[scroll_list.selectedIndex].text = ...

The webpage is produced with the following Perl code:

3. Avoid posting Perl to this newsgroup. Client-side Javascript
doesn't care how the page was generated.

Problem:
push ( \@BO_FO_EMAILS, t_area.value );

gives a javascript error "Error on Page". How do I update @BO_FO_EMAILS
within the javascript function saveText()?

4. Your Perl code runs on the server, exits (typically), and then
the page is sent to the client computer where the browser
displays it and the user makes a selection. @BO_FO_EMAILS
doesn't exist at the time that they make a selection.
 
W

William

William said:
My first time posting to clj , I have already read
http://jibbering.com/faq/#FAQ2_3 before posting.

javascript function in question:

saveText() is as follows:

function saveText( scroll_list, t_area, listToBeUpdated ) {
alert( listToBeUpdated.name );
// need to know which list to add the value in textarea back into
for(var i = 0; i < scroll_list.options.length; i++) {
if( scroll_list.options.selected == true ) {
scroll_list.options.text = t_area.value;
break;
}
}
// push new value to the corresponding scrolling_list
// then use this scrolling_list to update the dummylist
if ( listToBeUpdated.name == "bo_fo_emails" ) {
// push ( \@BO_FO_EMAILS, t_area.value );
}
}
Problem:
push ( \@BO_FO_EMAILS, t_area.value );

gives a javascript error "Error on Page". How do I update @BO_FO_EMAILS
within the javascript function saveText()?


4. Your Perl code runs on the server, exits (typically), and then
the page is sent to the client computer where the browser
displays it and the user makes a selection. @BO_FO_EMAILS
doesn't exist at the time that they make a selection.


I hear that by the time I run my javascript, the perl script had already
existed. but the question becomes how do I update a server-side file with
the newest values retrieved by the javascript?
 
D

David Wahler

William said:
I hear that by the time I run my javascript, the perl script had already
existed. but the question becomes how do I update a server-side file with
the newest values retrieved by the javascript?

You'll need to generate a new request from the client to the server
carrying your data, and then have the server-side script process it in
whatever way you need. Try researching XMLHttpRequest.

-- David
 
W

William

You'll need to generate a new request from the client to the server
carrying your data, and then have the server-side script process it in
whatever way you need. Try researching XMLHttpRequest.

I am currently using XMLHttpRequest as follows:
function saveText( scroll_list, t_area, listToBeUpdated ) {
var updated = new Option();
updated.value = t_area.value;
updated.text = t_area.text;
for(var i = 0; i < scroll_list.options.length; i++) {
if( scroll_list.options.selected ) {
scroll_list.options[scroll_list.selectedIndex].text = updated.value;
scroll_list.options[scroll_list.selectedIndex].value= updated.value;
break;
}
}
var confirmReq;
var url = "http://mkmxg00/cgi/confirmUpload.pl";
confirmReq = new ActiveXObject( "Microsoft.XMLHTTP" );
confirmReq.onreadystatechange = processReqChange;
confirmReq.open( "POST", url, true );
confirmReq.send( "" );

alert( url );
}

function processReqChange() {
if ( confirmReq.readyState == 4 ) {
if ( confirmReq.status == 200 ) {
alert( "passed!" );
}
}
else {
alert( confirmReq.readyState + ", " + confirmReq.status );
}
}

Where http://mkmxg00/cgi/confirmUpload.pl is as follows:
#!/usr/bin/perl -w

#===============================================================================
# confirmUpload.pl
# once the user clicks "Confirm Modifications", this script picks up the form's
# newest data from STDIN (POST method), then saves it to the dummylist
#===============================================================================

use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $query = new CGI;

# add code that reads in the "Confirm Modifications" request from the CGI
buffer
my $buffer;
read ( STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );

# buffer now contains data to be written to the dummylist
open ( OUTFD, "/mkapp/webapps/mxrt/data/extra_desk_tickers.txt" ) or
error("Couldn't open file: $DATAFILE\n");
print ( OUTFD $buffer );
close ( OUTFD );

exit 0;


My problem: nothing is written to
/mkapp/webapps/mxrt/data/extra_desk_tickers.txt

I have already invoked confirmUpload.pl with the XMLHttpRequest confirmReq
(I am using IE 6.0 on Windows XP). Why does the file contains no output
from the CGI buffer?
 
W

William

You'll need to generate a new request from the client to the server
carrying your data, and then have the server-side script process it in
whatever way you need. Try researching XMLHttpRequest.

I am currently using XMLHttpRequest as follows:
function saveText( scroll_list, t_area, listToBeUpdated ) {
var updated = new Option();
updated.value = t_area.value;
updated.text = t_area.text;
for(var i = 0; i < scroll_list.options.length; i++) {
if( scroll_list.options.selected ) {
scroll_list.options[scroll_list.selectedIndex].text =
updated.value;
scroll_list.options[scroll_list.selectedIndex].value=
updated.value;
break;
}
}
var confirmReq;
var url = "http://mkmxg00/cgi/confirmUpload.pl";
confirmReq = new ActiveXObject( "Microsoft.XMLHTTP" );
confirmReq.onreadystatechange = processReqChange;
confirmReq.open( "POST", url, true );
confirmReq.send( "" );

alert( url );
}

function processReqChange() {
if ( confirmReq.readyState == 4 ) {
if ( confirmReq.status == 200 ) {
alert( "passed!" );
}
}
else {
alert( confirmReq.readyState + ", " + confirmReq.status );
}
}

Where http://mkmxg00/cgi/confirmUpload.pl is as follows:
#!/usr/bin/perl -w

#===============================================================================
# confirmUpload.pl
# once the user clicks "Confirm Modifications", this script picks up the
form's
# newest data from STDIN (POST method), then saves it to the dummylist
#===============================================================================

use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $query = new CGI;

# add code that reads in the "Confirm Modifications" request from the CGI
buffer
my $buffer;
read ( STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );

# buffer now contains data to be written to the dummylist
open ( OUTFD, "/mkapp/webapps/mxrt/data/extra_desk_tickers.txt" ) or


The above line should read:
open ( OUTFD, ">/mkapp/webapps/mxrt/data/extra_desk_tickers.txt" ) or
error("Couldn't open file: $DATAFILE\n");

But the same problem remained. any help is appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top