Question about Javascript and Perl form

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

    Question about Javascript and Perl form

    Hello,

    I am trying to do something unusual and it has me stumped. I am looking to
    change the Env variable for RemoteUser essentially. What I would like to
    happen is that the user would choose a name from the dropdown box populated
    by the list in test.txt. Once the user chooses that name, the home
    directory is then pointed to the chosen name and the user is able to see the
    files listed in the new directory. I have included the snippet that I have
    been trying to accomplish this with and would gladly appreciate some
    feedback on how to make this happen.




    #my $user_file = "/Volumes/data01/cgi-bin/rem_user.txt";
    my $user_file = "test.txt";

    # The code sections generate the pulldown boxes in the slug form.
    #
    # Freeform fields are populated from cookies with inline perl.
    #

    print $query->header ( );

    print <<END_HTML;

    <HTML>
    <head>

    <script language="JavaS cript">

    function changeUser(user ){
    remoteuser = $user;
    homedir = "/Volumes/data01/Users/$remoteuser";
    alert("$homedir ");

    }



    </script>

    <link rel="stylesheet " href="/catch.css" type="text/css" />
    </head>
    <body>
    <div id="Header">
    <div id="MainText">

    <form action="/cgi-bin/slugreg"
    enctype="multip art/form-data" name="dataBuild " onSubmit="retur n
    verify(this.for m)" method="post">

    <h3> SLUG ENTRY FORM</h3>

    <table>
    <tr><td>
    <span CLASS="intable" >
    Select User Name:
    </td><td>


    END_HTML

    ############### ############### ############### ############### ############### #
    ############### ############
    ###Start Media Manager special###

    open (REMUSER, "$user_file ") || Error('open','f ile');
    #read (REMUSER);
    my @users = <REMUSER>;

    close (REMUSER);

    print "<select name='uname'>\n ";
    foreach (@users){
    print "<option value='$_'>$_'" ;
    }

    print "</select>\n";

    sub Error {
    print "Content type: text/html\n\n";
    print "The server cannot $_[0] the $_[1]: $! \n";
    exit;
    }
    ############### ############### ############### ############### ############### #
    ############### ###########

    print <<END_HTML;
    </td><td>
    <input type="button" name="test" value="Change User!"
    onClick="change User(document.d ataBuild.uname. options[document.dataBu ild.unam
    e.selectedIndex].value)">
    </td></tr>

    <tr><td>
    <span CLASS="intable" >
    Select File You've Uploaded:
    </td><td>
    <select name="photo">

    END_HTML

    # -------------------------------- code /
    html ---------------------------------

    # This code generates a list of files in their home directory for the file
    pulldown box

    opendir(DIRHAND LE, "$homedir") ;
    while ($name = readdir(DIRHAND LE)) {
    open(FILEHANDLE , "$homedir/$name");
    if ((-f FILEHANDLE) and ($name ne ".htaccess" ) and ($name ne ".DS_Store" ))
    {

    print "<option value='$name'>$ name\n";
    #end if
    }
    #end while
    }


  • Grant Wagner

    #2
    Re: Question about Javascript and Perl form

    Scott Medaugh wrote:
    [color=blue]
    > <script language="JavaS cript">[/color]

    <script type="text/javascript">
    [color=blue]
    > function changeUser(user ){
    > remoteuser = $user;[/color]

    Client-side JavaScript is not PHP, variables do not start with -$-. Besides,
    you're making an unnecessary assignment here.
    [color=blue]
    > homedir = "/Volumes/data01/Users/$remoteuser";[/color]

    var homedir = "/Volumes/data01/Users/" + user;
    [color=blue]
    > alert("$homedir ");[/color]

    Once again, client-side JavaScript is not PHP. Variables don't start with -$-
    and you can't embed a variable in a string and have it evaluate at run time. As
    a direct replacement for what you have there, it would be:

    alert(homedir);

    But I'd imagine you're actually looking for something like:

    location.href = homedir; // ?

    If this is your intent, personally I'd submit the form to the server, have it
    construct the appropriate URL path and then do print "Location: the/new/path";
    to redirect the browser there. Then you have no need for a client-side
    JavaScript dependence at all.

    --
    Grant Wagner <gwagner@agrico reunited.com>
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    Working...