Jump to content

[SOLVED] Using text area with php


sp@rky13

Recommended Posts

I am trying to use textarea so that I can have a select all thingo (a code box) but the stuff put in the text area is found using this:

<?php if ($pc=='')
	include "barbs_include_nopc.php";
	else if ($pc=='on')
	include "barbs_include_pc.php"?>

 

When I do that all the page does is echo that. It puts that code inside the textarea instead of executing it. How can I do it differently?

Link to comment
Share on other sites

Lol. What I have is a website that does this but what I want to add is a select all button. So I did that using this:

 

<!--

/*
Select All script- By JavaScript Kit(http://www.javascriptkit.com) 
Over 400+ free JavaScripts here!
*/

function selectAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
}
//-->
</script>
<a href="javascript:selectAll('test.select1')">Select All</a><br>
<form name="test">
<textarea name="select1" style="margin: 0px;
	padding: 6px;
	border: 1px inset;
	width: 250px;
	height: 200px;
	text-align: left;
	background-color: #FAFAD2 ;
	overflow: auto"><?php if ($pc=='')
	include "barbs_include_nopc.php";
	else if ($pc=='on')
	include "barbs_include_pc.php"?></textarea>
</form>

 

But the problem is that the php code doesn't execute as it should. So either i need it to be made s that it will execute or use a different select all box.

 

This is what is currently being used on the site but I don't know how I could add a select all button using javascript:

 

<pre name="test" style="
	margin: 0px;
	padding: 6px;
	border: 1px inset;
	width: 250px;
	height: 200px;
	text-align: left;
	background-color: #FAFAD2 ;
	overflow: auto"><?php if ($pc=='')
	include "barbs_include_nopc.php";
	else if ($pc=='on')
	include "barbs_include_pc.php"?></pre>

Link to comment
Share on other sites

You don't necessarily need to add a button.

 

Anyways, I threw this together for you:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Untitled Document</title>

	<script type="text/javascript">
		window.onload=function()
		{
			var selectAll = document.createElement("a");
			selectAll.setAttribute("href", "#");
			selectAll.setAttribute("id", "select_all");
			var selectAllText = document.createTextNode("Select All");
			selectAll.appendChild(selectAllText);
			var target = document.getElementById("target");
			document.getElementsByTagName("body")[0].insertBefore(selectAll, target);
			document.getElementById("select_all").onclick = function()
			{
				target.focus();
				target.select();
			}
		}
	</script>

</head>

<body>
	<textarea id="target">This is some text to be selected</textarea>
</body>
</html>

 

You can use that. I'm moving this to the javascript section though, since its a javascript issue.

Link to comment
Share on other sites

It's not working currently for some reason. Your's worked but when I integrated it into my webpage it didn't work????? So here's the entire webpages code:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
<title>Create Barb list</title>
<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
<?php $k1 = $_GET["k1"];?>
<?php $world = $_GET["world"];?>
<?php $pointsmin = $_GET["pointsmin"];?>
<?php $pointsmax = $_GET["pointsmax"];?>
<?php $p1 = $_GET["p1"];?>
<?php $p2 = $_GET["p2"];?>
<?php $pc = $_GET["pc"];?>
<script type="text/javascript">
         window.onload=function()
         {
            var selectAll = document.createElement("a");
            selectAll.setAttribute("href", "#");
            selectAll.setAttribute("id", "select_all");
            var selectAllText = document.createTextNode("Select All");
            selectAll.appendChild(selectAllText);
            var target = document.getElementById("target");
            document.getElementsByTagName("body")[0].insertBefore(selectAll, target);
            document.getElementById("select_all").onclick = function()
            {
               target.focus();
               target.select();
            }
         }
</script>
</head>
<body>
<div id="wrapper">
        <div id="header">
<a href="bbcodebarbs.php"><img src="images/bbcode_title.png" alt="Fake Script Maker" border="0"></a>
	</div>
         <div id="navigation">

<div class="container">
                        <ul id="navPyra">
<li><a href="index.php">Home</a></li>
<li><a href="fake_script.php">Fake Script Maker</a></li>
<li><a class="active"href="bbcodebarbs.php">BBCoded Barbs</a></li>
<li><a href="thanks_central.php">Thanks Central</a></li>
<li><a href="support.php">Support</a></li>
<li><a href="contact.php">Contact</a></li>

                        </ul>
                </div>
		   
	 </div>
	 		 </div>
<div id="content">
<textarea id="target" style="margin: 0px;
	padding: 6px;
	border: 1px inset;
	width: 250px;
	height: 200px;
	text-align: left;
	background-color: #FAFAD2 ;
	overflow: auto"><?php if ($pc=='')
	include "barbs_include_nopc.php";
	else if ($pc=='on')
	include "barbs_include_pc.php"?></textarea>
</div>
<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=5190901; 
var sc_invisible=1; 
var sc_partition=49; 
var sc_click_stat=1; 
var sc_security="2612f13c"; 
</script>

<script type="text/javascript"
src="http://www.statcounter.com/counter/counter.js"></script><noscript><div
class="statcounter"><a title="wordpress stats "
href="http://www.statcounter.com/wordpress.com/"
target="_blank"><img class="statcounter"
src="http://c.statcounter.com/5190901/0/2612f13c/1/"
alt="wordpress stats " ></a></div></noscript>
<!-- End of StatCounter Code -->	
</body>
</html>

 

So what's the problem. Also, if it's easier maybe having it where you click inside the area it would select the text.

 

Also, it's still not executing the php within the text area???? Why is this?. Can it be fixed?

Link to comment
Share on other sites

I wasn't thinking straight when I wrote that. Change this:]

 

document.getElementsByTagName("body")[0].insertBefore(selectAll, target);

 

to this:

 

target.parentNode.insertBefore(selectAll, target);

 

As to why your php isn't executing, there could be various reasons, but you should probably start a new thread in the PHP section for that, as its a completely different topic. Actually if the code I gave you above doesn't work, you will probably want to resolve your php issues first, as the results of your php problem could potentially be causing javascript problems.

 

But regardless, you should make the change I suggested above.

Link to comment
Share on other sites

Ok that fixed it. I would prefer if possible to have it that when you click inside the box, it selects it. Is that possible?

 

Also, for the php bit. It works fine when it's NOT in the text area. If I use something like this:

<pre name="test" style="
      margin: 0px;
      padding: 6px;
      border: 1px inset;
      width: 250px;
      height: 200px;
      text-align: left;
      background-color: #FAFAD2 ;
      overflow: auto"><?php if ($pc=='')
      include "barbs_include_nopc.php";
      else if ($pc=='on')
      include "barbs_include_pc.php"?></pre>

 

It actually executes. So maybe that is a php issue but I'd say it's html/javascript. What do you think?

Link to comment
Share on other sites

Ya, you're welcome. Oh wait, you didn't say thanks.

 

Anyways, it has nothing to do with the html or javascript - php is executed on the server before it even gets to the browser, which is where javascript and html are parsed.

 

Try adding curly braces:

 

<?php if ($pc=='')
      {include "barbs_include_nopc.php";}
      else if ($pc=='on')
      {include "barbs_include_pc.php"} ?>

 

They aren't always necessary, but its bad practice not to use them, because it's easy to miss things that way. It may also be because you didn't have a space before your closing php tag.

 

As for changing the code so that it works when you click on the textarea, change your whole javascript function to this:

 

<script type="text/javascript">
         window.onload=function()
         {
            var target = document.getElementById("target");
            target.onfocus = function()
            {
               this.select();
            }
         }
</script>

 

I didn't test it, but it should probably work.

Link to comment
Share on other sites

Yah but in the text box I have:

 

<?php if ($pc=='')
      {include "barbs_include_nopc.php";}
      else if ($pc=='on')
      {include "barbs_include_pc.php"} ?>

 

which ends up executing stuff which returns a results like this:

 

[village]490|601[/village]
[village]495|600[/village]

 

<br> is used for the line breaks. But now, when I do it, it writes br instead of doing the line break

Link to comment
Share on other sites

Do you actually realize what you are doing with that php function? You are including other files. Whatever is being displayed is the output from the other files. You haven't shown the contents of them in this thread, so right now it's impossible to say why that is happening. But regardless, you should open a new thread in the php help section, as this topic has been solved (and has been marked as such) and your new question has nothing to do with javascript or the original topic anymore.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.