Question about Javascript and Perl form

S

Scott Medaugh

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="JavaScript">

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="multipart/form-data" name="dataBuild" onSubmit="return
verify(this.form)" 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','file');
#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="changeUser(document.dataBuild.uname.options[document.dataBuild.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(DIRHANDLE, "$homedir");
while ($name = readdir(DIRHANDLE)) {
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
}
 
G

Grant Wagner

Scott said:
<script language="JavaScript">

function changeUser(user){
remoteuser = $user;

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

var homedir = "/Volumes/data01/Users/" + user;
alert("$homedir");

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top