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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • William

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

    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.opt ions.length; i++) {
    if( scroll_list.opt ions[i].selected == true ) {
    scroll_list.opt ions[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_emai ls" ) {
    // push ( \@BO_FO_EMAILS, t_area.value );
    }
    }

    The webpage is produced with the following Perl code:


    print $query->td(
    $query->textarea(-name=>'BOFOEmai ls',
    -onChange=>"save Text( this.form.bo_fo _emails,
    this.form.BOFOE mails,
    this.form.bo_fo _emails )"),
    $query->p,
    $query->button(-name=>'ADD',
    -value=>'Confirm Modifications',
    -onClick=>"move( index, this.form.BOFOE mails,
    this.form.bo_fo _emails)"),
    $query->button(-name=>'REMOVE',
    -value=>'Edit Selected Entry',
    -onClick=>"edit( this.form.bo_fo _emails,
    this.form.BOFOE mails)"));

    Basically, I am trying to remove scroll_list.opt ions[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.opt ions[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()?

  • William

    #2
    Re: JavaScript function saveText() needs to Update the Perl array

    On Fri, 20 Jan 2006, Lee wrote:
    [color=blue]
    > William said:[color=green]
    >>
    >> 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.opt ions.length; i++) {
    >> if( scroll_list.opt ions[i].selected == true ) {
    >> scroll_list.opt ions[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_emai ls" ) {
    >> // 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()?
    >>[/color]
    >
    > 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.[/color]

    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?

    Comment

    • David  Wahler

      #3
      Re: JavaScript function saveText() needs to Update the Perl array


      William wrote:[color=blue]
      > On Fri, 20 Jan 2006, Lee wrote:[color=green]
      > > 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.[/color]
      >
      > 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?[/color]

      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

      Comment

      • William

        #4
        Re: JavaScript function saveText() needs to Update the Perl array

        On Mon, 23 Jan 2006, William wrote:
        [color=blue]
        > On Fri, 20 Jan 2006, David Wahler wrote:
        >[color=green]
        >>
        >> William wrote:[color=darkred]
        >>> 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?[/color]
        >>
        >> 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.
        >>[/color]
        >
        > 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.opt ions.length; i++) {
        > if( scroll_list.opt ions[i].selected ) {
        > scroll_list.opt ions[scroll_list.sel ectedIndex].text =
        > updated.value;
        > scroll_list.opt ions[scroll_list.sel ectedIndex].value=
        > updated.value;
        > break;
        > }
        > }
        > var confirmReq;
        > var url = "http://mkmxg00/cgi/confirmUpload.p l";
        > confirmReq = new ActiveXObject( "Microsoft.XMLH TTP" );
        > confirmReq.onre adystatechange = processReqChang e;
        > confirmReq.open ( "POST", url, true );
        > confirmReq.send ( "" );
        >
        > alert( url );
        > }
        >
        > function processReqChang e() {
        > if ( confirmReq.read yState == 4 ) {
        > if ( confirmReq.stat us == 200 ) {
        > alert( "passed!" );
        > }
        > }
        > else {
        > alert( confirmReq.read yState + ", " + confirmReq.stat us );
        > }
        > }
        >
        > Where http://mkmxg00/cgi/confirmUpload.pl is as follows:
        > #!/usr/bin/perl -w
        >
        > #============== =============== =============== =============== =============== =====
        > # confirmUpload.p l
        > # 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(fatalsToBrow ser);
        >
        > my $query = new CGI;
        >
        > # add code that reads in the "Confirm Modifications" request from the CGI
        > buffer
        > my $buffer;
        > read ( STDIN, $buffer, $ENV{'CONTENT_L ENGTH'} );
        >
        > # buffer now contains data to be written to the dummylist
        > open ( OUTFD, "/mkapp/webapps/mxrt/data/extra_desk_tick ers.txt" ) or[/color]

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

        But the same problem remained. any help is appreciated.


        [color=blue]
        > 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_tick ers.txt
        >
        > I have already invoked confirmUpload.p l with the XMLHttpRequest confirmReq (I
        > am using IE 6.0 on Windows XP). Why does the file contains no output from
        > the CGI buffer?
        >
        >[/color]

        Comment

        • William

          #5
          Re: JavaScript function saveText() needs to Update the Perl array

          On Fri, 20 Jan 2006, David Wahler wrote:
          [color=blue]
          >
          > William wrote:[color=green]
          >> On Fri, 20 Jan 2006, Lee wrote:[color=darkred]
          >>> 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.[/color]
          >>
          >> 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?[/color]
          >
          > 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.
          >[/color]

          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.opt ions.length; i++) {
          if( scroll_list.opt ions[i].selected ) {
          scroll_list.opt ions[scroll_list.sel ectedIndex].text = updated.value;
          scroll_list.opt ions[scroll_list.sel ectedIndex].value= updated.value;
          break;
          }
          }
          var confirmReq;
          var url = "http://mkmxg00/cgi/confirmUpload.p l";
          confirmReq = new ActiveXObject( "Microsoft.XMLH TTP" );
          confirmReq.onre adystatechange = processReqChang e;
          confirmReq.open ( "POST", url, true );
          confirmReq.send ( "" );

          alert( url );
          }

          function processReqChang e() {
          if ( confirmReq.read yState == 4 ) {
          if ( confirmReq.stat us == 200 ) {
          alert( "passed!" );
          }
          }
          else {
          alert( confirmReq.read yState + ", " + confirmReq.stat us );
          }
          }

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

          #============== =============== =============== =============== =============== =====
          # confirmUpload.p l
          # 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(fatalsToBrow ser);

          my $query = new CGI;

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

          # buffer now contains data to be written to the dummylist
          open ( OUTFD, "/mkapp/webapps/mxrt/data/extra_desk_tick ers.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_tick ers.txt

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

          Comment

          Working...