Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts

    PERL/JavaScript interaction

    I have a PERL script which includes a textbox within a form name "inpform" where users can type a message. This works fine but I would like to modify it so that when they click on the textarea (the first time) the contents which reads "Your reminder message here" is erased ready for them to type their message.

    I made a JavaScript [function clearit()] to do this which works fine in a simple HTML page, but for some reason is not called by onclick="clearit()" in the HTML within the PERL script. There is no syntax error - just nothing happens.

    Here is a fragment of the program:-

    ---------------------------------------------------

    print "</select></td></tr>

    <tr><td colspan=2><hr color=#008080></td></tr>
    <tr><th align=center colspan=2>Please enter a reminder message for yourself:</th></tr>

    <tr><td align=center colspan=2>
    <textarea name=Message cols=54 rows=5 onclick=\"clearit()\">Your reminder message here.</textarea></td></tr>

    <SCRIPT language=\"JavaScript\" >
    var clearbox = 0;
    function clearit() {
    if (clearbox == 0) {
    document.inpform.Message.value = \"\";
    clearbox = 1;
    }
    }
    </SCRIPT>

    <SCRIPT language=\"JavaScript\">getBgn();</SCRIPT>

    -------------------------------------------------------------------

    Any help would be much appreciated. I guess it is something stupidly simple.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,503
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    not quite enough script for me to test it out, but try this
    just for the fun of it ... I don't know if it will work or not:

    use the same exact code on your "working" script as the
    one you use with Perl. Use the alternate way to print, so
    you can use the same exact code ... without escaping
    the quotes.
    ---------------------------------------------------
    #somewhere at the top, you begin with print << EOT;
    #after that, you can use quotes as normal.
    #at the end, you end with EOT


    print <<EOT;
    Content-type: text/html

    </select></td></tr>

    <tr><td colspan=2><hr color=#008080></td></tr>
    <tr><th align=center colspan=2>Please enter a reminder message for yourself:</th></tr>

    <tr><td align=center colspan=2>
    <textarea name=Message cols=54 rows=5 onclick="clearit()">Your reminder message here.</textarea></td></tr>

    <SCRIPT language="JavaScript" >
    var clearbox = 0;
    function clearit() {
    if (clearbox == 0) {
    document.inpform.Message.value = "";
    clearbox = 1;
    }
    }
    </SCRIPT>

    <SCRIPT language="JavaScript">getBgn();</SCRIPT>

    EOT

    -------------------------------------------------------------------

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Thank you very much for your suggestion. however, the JavaScript still does not work.

    My code is now:-

    print <<EOT;
    Content-type: text/html

    </select></td></tr>
    <tr><td colspan=2><hr color=#008080></td></tr>
    <tr><th align=center colspan=2>Please enter a reminder message for yourself:</th></tr>

    <tr><td align=center colspan=2>
    <textarea name=Message cols=54 rows=5 onclick="clearit()">Your reminder message here.</textarea></td></tr>

    <SCRIPT language="JavaScript" >
    var clearbox = 0;
    function clearit() {
    if (clearbox == 0) {
    document.inpform.Message.value = "";
    clearbox = 1;
    }
    }
    </SCRIPT>

    EOT

    I do not understand what is wrong, as there are other JavaScripts incorporated in the HTML which do work. As I say, there is no syntax error, the clearit() function is just not called.

    print "$header

    <form name = \"inpform\" method=POST action=$cgi_url>

    Is this the problem, i.e. \"inpform\" not being recognised by
    document.inpform.Message.value = "";

    Last edited by Philip M; 12-16-2004 at 07:55 AM.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,503
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    The script below actually works ... I tried it.
    I did the print thing a little different this time.

    Here's the working link: http://www.catpin.com/cgi-bin/jav.pl



    =======================================================

    #!/usr/bin/perl
    #

    print "Content-type: text/html \n\n";

    print qq~
    <html><body><table>
    <form name="inpform" method=POST action=$cgi_url>

    <tr><td colspan=2><hr color=#008080></td></tr>
    <tr><th align=center colspan=2>Please enter a reminder message for yourself:</th></tr>

    <tr><td align=center colspan=2>
    <textarea name=Message cols=54 rows=5 onclick="clearit()">Your reminder message here.</textarea></td></tr>

    <SCRIPT language="JavaScript" >
    var clearbox = 0;
    function clearit() {
    if (clearbox == 0) {
    document.inpform.Message.value = "";
    clearbox = 1;
    }
    }
    </SCRIPT>

    <SCRIPT language="JavaScript">getBgn();</SCRIPT>
    </form></table></body></html>

    ~;

  • #5
    Regular Coder
    Join Date
    Sep 2004
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i tihnk

    <textarea name=Message cols=54 rows=5 onFocus="this.value=''">Your reminder message here.</textarea>

    would do the job without all that scripting

    .....

    however i now realise that your version has the added feature of not deleting it again when you have clicked somewhere else
    Last edited by andyede; 12-16-2004 at 01:54 PM.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    "however i now realise that your version has the added feature of not deleting it again when you have clicked somewhere else"

    Well, yes. It is not much use if the user cannot edit his message text without deleting it!

    still

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,503
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Phillip ...

    Did you try the script in the previous couple threads?
    The one with the actual working example?

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Sorry, I jumped over your most recent response by mistake.

    I have altered my script as per yours but it still does not work for me.
    It is just a fragment of a rather large code block which I am reluctant to post in its entirety as it would consume a lot of space.

    I note that your test example (thank you very much indeed for your trouble here) works as intended, but throws a JavaScript error Line 21 Character 1 Error: object expected. I don't understand this either, and the script actually works, but does it offer any clue why it does not work for me?

    It is not too vital, just a marginal improvrement which I thought would be easy but there is some glitch which prevents the JavaScript from being called (I have determined this with suitable alerts).

    Again, tahnk you for your help. I will continue to work on it!

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Ah well, here is the whole block (with some non-relevant bits cut out)

    Code:
    sub show_main_screen {
    
    print qq~
    Content-type: text/html
    $header
    <center> <strong>
    $_[0]
    <br>$errorlist</strong><br>
    
    <form name = "inpform"  method=POST  action=$cgi_url>
    ~;
    
    print "<table border=0>    ## Start of print block
    <tr><th align=left colspan=2>$reminder_page_text</th></tr>
    <tr><td colspan=2><hr color=#008080>
    <font size=\"-1\" color=\"#FF0000\">Reminders will be sent to $data{'Email'}. 
    &nbsp &nbsp  <font color=\"#000000\">
    <a href=\"$cgi_url?FA=Register\">Or, register a new email address</a>
    </font></td></tr>
    <input type=hidden name=Email size=15 value=\"$data{'Email'}\">
    <input type=hidden name=Password size=15 value=\"$data{'Password'}\">
    <tr><th align=left>Send the reminder(s) starting</th>
    <td><select name=Remindme>
    <option value=1>1 day before the date
    <option value=3>3 days before the date
    <option value=7>1 week before the date
    <option value =14>2 weeks before the date
    <option value=21>3 weeks before the date
    <option value=30>1 month before the date
    <option value=180>6 months before the date
    </select></td></tr>
    <tr><th align=left>Remind&nbsp;me&nbsp;how&nbsp;often&nbsp;about&nbsp;this&nbsp;date</th>
    <td><select name=Sendme>
    <option>Once Only
    <option>Annually
    <option>Semi-Annually
    <option>Quarterly
    <option>Bi-Monthly
    <option>Monthly
    <option>Bi-Weekly
    <option>Weekly
    <option>Daily
    </select>
    &nbsp &nbsp
    
    <SCRIPT language=\"JavaScript\">
    function kph_popup_message (kph_message) {
     alert (kph_message);
     return false;
    }
    </SCRIPT>
    <font size=\"-1\"><a href=\"\" onClick=\"return kph_popup_message('Instructions in here.');\">Please Explain This</a></font>
    
    </td></tr>
    <tr><th align=left>Date to Remember:</th><td><select name=Day>";  ## End of print block
    
      ($tday,$tmon,$tyear) = &get_date_as_numbers(time);
      for($i = 1; $i <= 31; $i++){
         if($i == $tday + 1){ $ck = " SELECTED"; } else { $ck = ""; }
         print "<option$ck>$i</option>\n";
         }
    print "</select> <select name=Month>\n";
      %mon_by_value = reverse %months;
      foreach $key (sort {$a <=> $b } (keys(%mon_by_value))){
         if($key eq $tmon){
    	$ck = " SELECTED";
         } else {
    	$ck = "";
    	}
         print "<option$ck>$mon_by_value{$key}\n";
         }
      print "</select> <select name=Year>\n";
      $tyear += 1900;
      for ($i = $tyear; $i < $tyear + 10; $i++){
         if($tyear eq $i){$ck = " SELECTED"; } else {$ck = "";}
         print "<option$ck>$i</option>\n";
         }
      
    print qq~
    Content-type: text/html
    
    </select></td></tr>
    <tr><td colspan=2><hr color=#008080></td></tr>
    <tr><th align=center colspan=2>Please enter a reminder message for yourself:</th></tr>
    
    <tr><td align=center colspan=2>
    <textarea name=Message cols=54 rows=5 onClick="clearit()">Your reminder message here.</textarea></td></tr>
    
    <SCRIPT language="JavaScript" >
    var clearbox = 0;
    function clearit() {
    alert (clearbox);
    if (clearbox == 0) {
    document.inpform.Message.value = "TESTING INPFORM";
    document.forms[0].Message.value = "WITH FORMS 0";
    clearbox = 1;
    }
    }
    </SCRIPT>
    ~;
    
    print "<br>
    <tr><input type=hidden name=Formaction value=Add>
    <td colspan=2 align=center><input type=submit value=\" Add This Reminder \"></td></tr>
    </form>
    </table></center>
    
    $footer";
    exit();
    
    }

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,503
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Quote Originally Posted by Philip M
    It is not too vital, just a marginal improvrement which I thought would be easy but there is some glitch which prevents the JavaScript from being called (I have determined this with suitable alerts).
    I know what you mean ...

    It gets frustrating, but it really is important to get it working even if
    you don't need it. You'll learn something you might need later on.
    I learn so many things just from looking at the threads on this forum.

    I suggest trying a simpler Javascript within a Perl script ... maybe
    a simple "hello world" kind of thing. That would answer the question
    of Javascripts not being seen within your Perl scripts. It's possible
    that this might be a set-up problem with your CGI-BIN.

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by mlseim
    I know what you mean ...

    It gets frustrating, but it really is important to get it working even if
    you don't need it. You'll learn something you might need later on.
    I learn so many things just from looking at the threads on this forum.

    Yes, my thoughts exactly! It will bug me if I cannot get this to work. I am
    not a professional programmer but I do usually manage to sort these things out.

    I really am baffled. The fault is not in the script, it is simply not called by the HTML onClick="clearit()". The program runs just as though it was not there. And there are other Javascripts in the program which work just fine.

    Once more, thank you very much indeed for your time and trouble - I really appreciate it. Season's Greetings to you!

  • #12
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,503
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Just one more thought ...

    Have you tried putting this part in between <head> and </head>?

    <SCRIPT language="JavaScript" >
    var clearbox = 0;
    function clearit() {
    alert (clearbox);
    if (clearbox == 0) {
    document.inpform.Message.value = "TESTING INPFORM";
    document.forms[0].Message.value = "WITH FORMS 0";
    clearbox = 1;
    }
    }
    </SCRIPT>

  • #13
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Nope. Doesn't work either.
    Still baffled!
    But very many thanks once again.

  • #14
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Eureka! Problem solved!

    This was quite subtle and i will try to explain in case anyone else has this problem.

    My existing program is called program.cgi. I made a copy as testprogam.cgi
    to which I added the JavaScript. But I failed to notice that within the PERL is a call to a variable called $url which is set to point to functions within program.cgi. So although the running program was testprogram.cgi it in effect switched to program.cgi for this page. In other words, the new part of testprogram.cgi was never called, so of course the script did not work.
    I found this out by using the browser's "view source" facility.

    I guess that more experienced programmer would not have fallen for this.
    I am only a hammer chewer.



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •