nex1234 Posted July 6, 2008 Share Posted July 6, 2008 Hi all, I'm new to this forum and to javascript. I've been successful at producing a script that allows me to view and update text from a cell in a database table. However, the script only allows me to see a small portion of the cell contents. I would like to be able to place the contents of the cell in a "textarea" using cols & rows to set the textarea height but I cannot figure out where to place the textarea function. I tried for hours using trial & error but no luck. I'm hoping someone can help. Here's the code and thank you. <?php if(!isset($_GET['table'])) { die("You must have a table name set in the query string."); } $table = $_GET['table']; $id = $_GET['id']; mysql_connect("---", "---", "---"); mysql_select_db("---"); function returnheaders() { global $table; $sql = mysql_query("SELECT * FROM `$table` LIMIT 1") or die(mysql_error()); // `` enables table names with #'s $array = mysql_fetch_array($sql); foreach($array as $key => $value) { if(!is_numeric($key) && $key != "id") { echo("<td id=\"header_$key\">$key</td>\n"); } } } function returndata() { global $table; global $id; $sql = mysql_query("SELECT * FROM `$table` WHERE id=$id"); // `` enables table names with #'s while($row = mysql_fetch_array($sql)) { echo("<tr id=\"dataset_row".$row['id']."\">\n"); foreach($row as $key => $value) { if(!is_numeric($key) && $key != "id") { echo("<td id=\"".$key.$row['id']."\" nowrap><a id=\"".$key."_".$row['id']."_value\" href=\"javascript:edit_row(".$row['id'].");\">".$value."</a></td>\n"); } } echo("</tr>\n"); echo("</textarea>"); } } function loaddynamicjava() { global $table; echo("<script type=\"text/javascript\">\nvar readylight = true;\nfunction edit_row(row) {\nvar currentval;\n"); $sql = mysql_query("SELECT * FROM `$table` WHERE id=1") or die(mysql_error()); // `` enables table names with #'s $array = mysql_fetch_array($sql); foreach($array as $key => $value) { if(!is_numeric($key) && $key != "id") { echo("currentval = document.getElementById(\"".$key."_\"+row+\"_value\").innerHTML;\n"); echo("document.getElementById(\"".$key."\"+row).innerHTML = "); if($key == "Date") echo("'<input type=\"button\" name=\"save\" value=\"Save\" onClick=\"savedata('+row+');\">"); else echo("'"); echo("<input type=\"text\" id=\"".$key."_'+row+'\" name=\"".$key."_'+row+'\" value=\"'+currentval+'\" />';\n"); } } echo("}\nfunction savedata(row) {\nif(!ready) { alert(\"Database is still saving other data!\"); return; }\nready = false;\nvar currentdata;"); foreach($array as $key => $value) if(!is_numeric($key)) if($key == "id") echo("document.getElementById(\"id\").value = row;\n"); else echo("document.getElementById(\"".$key."\").value = document.getElementById(\"".$key."_\"+row).value;\n"); echo("document.getElementById(\"theform\").submit();\n"); foreach($array as $key => $value) if(!is_numeric($key) && $key != "id") { echo("currentdata = document.getElementById(\"".$key."_\"+row).value;\n"); echo("document.getElementById(\"".$key."\"+row).innerHTML = '<a href=\"javascript:edit_row('+row+');\" id=\"".$key."_'+row+'_value\">'+currentdata+'</a>';\n"); } echo("}\nfunction nowready() { ready = true; }</script>"); } function returnformfields() { global $table; $sql = mysql_query("SELECT * FROM `$table` LIMIT 1"); // `` enables table names with #'s $array = mysql_fetch_array($sql); foreach($array as $key => $value) if(!is_numeric($key)) echo("<input type=\"hidden\" name=\"".$key."\" id=\"".$key."\" />\n"); echo("<input type=\"hidden\" name=\"table\" value=\"$table\" />\n"); } ?> <?php loaddynamicjava(); ?> <body> <b><u>MPS PROJECT TRACKING</u></b><br /><br /> <a href="javascript:history.back();">Back</a> <a href="../home.php">Home</a><br /><br /> <table border="1" cellpadding="0" cellspacing="0"> <tr class="header"><?php returnheaders(); ?></tr> <?php returndata(); ?> </table> <form action="update_edit.php" method="post" target="hiddenframe" name="theform" id="theform"> <?php returnformfields(); ?> </form> <br /> <a href="javascript:window.print();">Print this page.</a> <iframe src="about:blank" style="display: none;" name="hiddenframe" id="hiddenframe" onLoad="nowready();">This page requires iFrames which your browser does not support.</iframe> </body> </html> [code] [/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.