By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,902 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

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

P: n/a
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[i].selected == true ) {
scroll_list.options[i].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[i].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[i].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()?

Jan 20 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Fri, 20 Jan 2006, Lee wrote:
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[i].selected == true ) {
scroll_list.options[i].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?

Jan 20 '06 #2

P: n/a

William wrote:
On Fri, 20 Jan 2006, Lee wrote:
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?


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

Jan 20 '06 #3

P: n/a
On Mon, 23 Jan 2006, William wrote:
On Fri, 20 Jan 2006, David Wahler wrote:

William wrote:
On Fri, 20 Jan 2006, Lee wrote:
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?
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[i].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.
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?

Jan 23 '06 #4

P: n/a
On Fri, 20 Jan 2006, David Wahler wrote:

William wrote:
On Fri, 20 Jan 2006, Lee wrote:
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?


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[i].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?

Jan 23 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.