Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 6th, 2007, 12:04 AM   #1
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 707
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
Old Feb 6th, 2007, 3:30 AM   #2
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
I'm not so sure I can identify what the problem is but the $session->logged_in doesn't make much sense if you haven't declared $session somewhere to be a new type of object. Unless you're trying to refer to the session superglobal array somehow, but for PHP 5 that would be of the sort $_SESSION, and you'd have to test that it's set or something. Not exactly sure what you're going for.

Furthermore I think javascript is unnecessary in what you're trying to achieve. If you're already using javascript might as well just do everything with it. In other words the use of the form isn't exactly necessary. To stick with PHP I would suggest using 3 radio buttons something of the form:
<input type="radio" name="type" value="delete"> Delete
<input type="radio" name="type" value="edit"> Edit
<input type="radio" name="type" value="share"> Share
Then it just becomes a matter of checking $_POST['type'] for the given operation you wish performed. Could even do it with numbers rather than strings:
<input type="radio" name="type" value="0"> Delete
<input type="radio" name="type" value="1"> Edit
<input type="radio" name="type" value="2"> Share
This would allow you to perform a switch statement for each particular case:
switch((int)$_POST['type']){
case 0: ...  // Delete code
case 1: ...  // Edit code
case 2: ...  // Share code
default: ... // In case of an error
}
I don't know that these suggestions actually help the problem you're currently experiencing which seems to be more of a session problem than it does a javascript or php error.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Feb 6th, 2007, 10:08 AM   #3
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 707
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
Grimppirate, it's my fault for not including the entire script, I was trying to cut back on how much code you guys had to search through. At the beginning of the code is
[php]
<?
include("include/session.php");
?>
[/php]
thechristelegacy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling Maverik 6.2 (from C) megamind5005 C 16 May 3rd, 2006 5:41 PM
libraries matko C 1 Jan 22nd, 2006 2:12 PM
Php Postgresql Class Pizentios Show Off Your Open Source Projects 15 Jun 28th, 2005 9:55 AM
Jackpot game zorin Visual Basic 3 Jun 10th, 2005 1:19 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:38 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC