+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Just Another Geek SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403

    Client-Side PerlScript

    Hi all. I'm going nuts... I cannot get this thing to work.. Must be doing something wrong but I can't figure out what...

    Here's a code example:
    Code:
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <TITLE>formtest</TITLE>
    </HEAD>
    <BODY>
    <FORM NAME=myform>
    <INPUT TYPE=text NAME=mytest>
    <INPUT TYPE=submit>
    </FORM>
    <SCRIPT LANGUAGE=PerlScript>
    $mytest = $window->document->myform->mytest->{'Value'};
    
    $window->document->write("Debug: $mytest\n");
    
    </SCRIPT>
    </BODY>
    </HTML>
    It has no errors. But I cannot seem to get the value of the textfield...

    I'm using ActivePerl 5.8, IE6 on WinXP.
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  2. #2
    Senior Member zENGER zENGER zENGER zENGER zENGER zENGER zENGER zENGER zENGER zENGER zENGER
    Join Date
    Jul 2004
    Posts
    469
    When the page loads, and the code is parse, the text box is empty.

  3. #3
    Just Another Geek SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    Yes. But when I type something in there and click on submit..
    I can see the page reloading with "?mytest=thetextityped" appended..
    The textbox shows the typed text but the variable stays empty..
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  4. #4
    Senior Member zENGER zENGER zENGER zENGER zENGER zENGER zENGER zENGER zENGER zENGER zENGER
    Join Date
    Jul 2004
    Posts
    469
    Is the text box blank in the second instance? I've never used perlscript so I'm only gandering here, but I would guess that when you initialize the form the second time, its clearing the value. Also, should you be referencing the form or the retained data?

  5. #5
    Hi mom! Guus Guus Guus Guus Guus Guus Guus Guus Guus Guus Guus
    Join Date
    Aug 2001
    Posts
    1,103
    I never used perlscript before, but as I'm seeing it, you're never suppling a value for your textfield. That way, the contents of that textfield will always be empty. Try this:

    Code:
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <TITLE>formtest</TITLE>
    </HEAD>
    <BODY>
    <FORM NAME="myform" METHOD="GET">
    <INPUT TYPE="text" NAME="mytest" VALUE="Foo">
    <INPUT TYPE="submit">
    </FORM>
    <SCRIPT LANGUAGE="PerlScript">
    $mytest = $window->document->myform->mytest->{'Value'};
    
    $window->document->write("Debug: $mytest\n");
    
    </SCRIPT>
    </BODY>
    </HTML>
    I can't test it, since I have no activeperl installed. You should get something in your textbox, and that same word should be printed in the body of your page, as far as I see.

    By the way: you should also specify that your form uses the GET method to send those variables (<FORM NAME="yadda" METHOD="GET"&gt.
    I wish to express my gratitude to the people of Italy. Thank you for inventing pizza.

  6. #6
    Senior Member sec_ware has a reputation beyond repute sec_ware has a reputation beyond repute sec_ware has a reputation beyond repute sec_ware has a reputation beyond repute sec_ware has a reputation beyond repute sec_ware has a reputation beyond repute sec_ware has a reputation beyond repute sec_ware has a reputation beyond repute sec_ware has a reputation beyond repute sec_ware has a reputation beyond repute sec_ware has a reputation beyond repute
    Join Date
    Mar 2004
    Posts
    557
    Hi

    I think, the problem lies in the submit button. The parameters are
    sent by GET/POST, which might complicate things unnessarily for
    client-side scripting. I would try to replace the submit with an ordinary
    button, or just call a PerlScript-function onclick.

    Code:
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <TITLE>formtest</TITLE>
    </HEAD>
    <BODY>
    <FORM NAME=myform>
    <INPUT TYPE=text NAME=mytest>
    <INPUT TYPE=submit onclick="my_perlfunction">
    </FORM>
    <SCRIPT LANGUAGE=PerlScript>
    sub my_perlfunction {
    
    $mytestvalue = $window->document->myform->mytest->{'Value'};
    $window->document->write("Debug: $mytestvalue\n");
    }
    </SCRIPT>
    </BODY>
    </HTML>
    or

    Code:
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <TITLE>formtest</TITLE>
    </HEAD>
    <BODY>
    
    <FORM NAME="myform">
    <INPUT TYPE="text" ID="id_mytest">
    <INPUT TYPE="button" onclick="my_perlfunction" value="Submit Query">
    </FORM>
    
    <SCRIPT LANGUAGE="PerlScript">
    sub my_perlfunction {
    
    $testelement = $window->document->getElementById("id_mytest")->value;
    $window->document->write("Debug: $testelement\n");
    }
    
    </SCRIPT>
    </BODY>
    </HTML>
    I'd go with the ID-version, which is standard (?) for passing values from
    one scripting language to another.

    Cheers.
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  7. #7
    Just Another Geek SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    Thanx guys.. I'm a bit closer now.. removed the submit button (it was for test anyway) and used an <SELECT> in combination with an ID field..
    Code:
    <HTML>
    <HEAD><TITLE>TEST</TITLE>
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <SCRIPT LANGUAGE=PerlScript>
    sub mychange {
    	my $aa = $window->document->getElementByID("mytest")->value;
    	$window->document->write("<h1>Debug: $aa</h1>");
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM><SELECT ID=mytest onChange="mychange();">
    <OPTION VALUE=1>Choice 1</OPTION>
    <OPTION VALUE=2>Choice 2</OPTION>
    </SELECT></FORM>
    </BODY>
    </HTML>
    Btw this works too:
    Code:
    <HTML>
    <HEAD><TITLE>TEST</TITLE>
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <SCRIPT LANGUAGE=PerlScript>
    sub mychange {
    	my $aa = $window->document->myform->myselect->{'Value'};
    	$window->document->write("<h1>Debug: $aa</h1>");
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM NAME=myform><SELECT NAME=myselect onChange="mychange();">
    <OPTION VALUE=1>Choice 1</OPTION>
    <OPTION VALUE=2>Choice 2</OPTION>
    </SELECT></FORM>
    </BODY>
    </HTML>
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  8. #8
    Just Another Geek SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute SirDice has a reputation beyond repute
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    Just for kicks here's a variation:
    Code:
    <HTML>
    <HEAD><TITLE>TEST</TITLE>
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <SCRIPT LANGUAGE=PerlScript>
    sub myform::klik_onClick {
    	my $aa = $window->document->myform->myselect->{"Value"};
    	$window->document->write("<h1>klik: $aa</h1>");
    }
    sub myform::myselect_onChange {
    	my $aa = $window->document->myform->myselect->{"Value"};
    	$window->document->write("<h1>change: $aa</h1>");
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM NAME=myform><SELECT NAME=myselect>
    <OPTION VALUE=1>Choice 1</OPTION>
    <OPTION VALUE=2>Choice 2</OPTION>
    </SELECT><INPUT TYPE=button VALUE="Go" NAME=klik></FORM>
    </BODY>
    </HTML>
    This one doesn't seem to like ID's though.. If I try to use ID's the onChange doesn't work anymore. Even if I use NAME and ID fields.. Same values and/or different ones for NAME/ID.

    Oh well, got enough to get me going
    Oliver's Law:
    Experience is something you don't get until just after you need it.

Bookmarks

Posting Permissions

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

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides