![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
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>] " ."[<a href=\"useredit.php\">Edit Account</a>] " ."[<a href=\"saver.php\">New Document</a>] "; if($session->isAdmin()){ echo "[<a href=\"admin/admin.php\">Admin Center</a>] "; } 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 /////////////////////////// |
|
|
|
|
|
#2 |
|
King of Portal
|
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 <input type="radio" name="type" value="0"> Delete <input type="radio" name="type" value="1"> Edit <input type="radio" name="type" value="2"> Share switch((int)$_POST['type']){
case 0: ... // Delete code
case 1: ... // Edit code
case 2: ... // Share code
default: ... // In case of an 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 |
|
|
|
|
|
#3 |
|
Expert Programmer
|
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] |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compiling Maverik 6.2 (from C) | megamind5005 | C | 16 | May 3rd, 2006 6:41 PM |
| libraries | matko | C | 1 | Jan 22nd, 2006 3:12 PM |
| Php Postgresql Class | Pizentios | Show Off Your Open Source Projects | 15 | Jun 28th, 2005 10:55 AM |
| Jackpot game | zorin | Visual Basic | 3 | Jun 10th, 2005 2:19 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 5:12 PM |