View Single Post
Old Feb 6th, 2007, 1:04 AM   #1
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 708
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
javascript function over table

Ok, so I wrote some code to make links act like the submit button to a form. I wrote a test file (test.php) which used analyze.php to work with the form data. When I put it up to the scale on the main page the javascript stopped work, so I'm thinking it's because I'm putting it into a table, below is the code. Any ideas or thoughts is much appreciated! Thanks guys!

test.php
[php]
<html>
<script language="JavaScript" type="text/javascript">
<!--
function submit ( selectedType )
{
document.form1.value.value = selectedType ;
document.form1.submit() ;
}
-->
</script>
<form name="form1" method="post" action="analyze.php">
<input type="hidden" name="value" />
<a href="javascript:submit('Delete')">Delete</a> or
<a href="javascript:submit('Edit')">Edit</a>or
<a href="javascript:submit('Share')">Share</a>
</form>
</html>
[/php]

analyze.php
[php]
<html>
<body>
<?php
$file = $_POST['value'];

echo $file;

if ($file == 'Delete')
{
echo "Delete has been chosen.";
}
elseif ($file =='Edit')
{
echo "Edit function has been chosen.";
}
elseif ($file =='Share')
{
echo "Share function has been chosen.";
}
else
{
echo "Nothing has been chosen.";
}

?>
</body>
</html>
[/php]

And when I use test.php everything works, now below is the code that uses it in a table and doesn't work. I

main.php (The entire file is not included. If you think the problem could be in the rest of the file, let me know, but I think it's a waste of space and tiem for you guys to look at)
[php]
html>

<body>
<script language="JavaScript" type="text/javascript">
<!--
function submit ( selectedType )
{
document.form1.value.value = selectedType ;
document.form1.submit() ;
}
-->
</script>
<table>
<tr><td>


<?
if($session->logged_in){
echo "<h1>Logged In</h1>";
echo "Welcome <b>$session->username</b>!<br><br>"
."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;"
."[<a href=\"saver.php\">New Document</a>] &nbsp;&nbsp;";
if($session->isAdmin()){
echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";
}
echo "[<a href=\"process.php\">Logout</a>]<br><br><br>- [$session->username's Files] -<br>";


// -------------------------------------------------------------------------------------------------- Directory Code
// This is the directory to list files for.
$theDirectory = $session->username;
// Do you want to show directories? change to false to hide directories.
$listDirectories = false;
echo "</ br></ br>";
if(is_dir($theDirectory))
{
// Title for top of columns
echo "<table><tr>
<td><u>Name</u></td>
<td><u>Size</u></td>
<td><u>Action</u></td>
<td><u>Action</u></td>
<td><u>Action</u></td>
<td><u>Action</u></td>
</tr>";
$dir = opendir($theDirectory);
while(false !== ($file = readdir($dir)))
{
$type = filetype($theDirectory ."/". $file);
if($listDirectories || $type != "dir")
{
echo "<tr><td>" . $file . "</td>";
// echo "<td>" . $type . "</td>";

echo "<td>";
if($type == "file")
$fileSize = filesize($theDirectory."/".$file)/1024; // Divide 1024 to get into kilobytes
echo number_format($fileSize, 2); // Limit the decimals to two places
echo " Kilobytes.";
echo "</td>";

echo "<td><a href='".$theDirectory."/".$file."'>View</a></td>"; // Works

////////////////////////////////////////////////////////////////////////////////


echo "<form name\"form1\" method=\"post\" action=\"analyze.php\">";
echo "<input type=\"hidden\" name=\"value>";
echo "<td><a href=\"javascript:submit('Edit')\">Edit</a></td>"; // Doesn't Work
echo "<td><a href=\"javascript:submit('Delete')\">Delete</a></td>"; // Doesn't Work
echo "<td><a href=\"javascript:submit('Share')\">Share</a></td>"; // Doesn't Work
echo "</form>";


echo "</tr>";
////////////////////////////////////////////////////////////////////////////
}
}
closedir($dir);
echo "</table>---";
}
else
{
echo $theDirectory . " is not a directory";
}
//----------------------------------------------------------------------------------------------------------------------------------------------End Directory Code
[/php]

I enclosed what I think to be the problematic area in ///////////////////////////
thechristelegacy is offline   Reply With Quote