php, iframe and javascript help please

Associate
Joined
29 Mar 2004
Posts
593
Location
Cambs, UK
Hi folks,

Im currently coding a website, and doing the cms part at the moment.

Im having problems with adding content into my textarea input.

What im trying to do is when i click on a link, it adds the text into the textarea. I have it working fine when the link is in the same page as the textarea, but i was wondering how i refer to the textarea that is in a different page, for example.

document 1 has a textarea in it.
document 2 has a load of links in it.

When i click a link in document 2, i want the text to be added to the textarea in document 1.

Im using an iframe in document 1 that displays all the links in document 2.

The code i am using to add text to the textarea is as follows.

PHP:
<html>
<head>
<script language="javascript">
function addtext(newtext)
{
	document.add.content.value=document.add.content.value+=newtext;
}
</script>
</head>
<body>
<?php

$path="./images/work";
$images=opendir($path);
while(($file=readdir($images)) !==false)
{
	if($file=="." || $file=="..")
	{
	}
	else
	{
	echo "<a href='$path/$file' target='_blank'><img src='$path/$file' width='50'/></a>";
	echo "<a href=javascript:addtext('picture');>$file</a><br/>";
	}
}
closedir($images);
?>
</body>
</html>

What im trying to find out is how to reference a different document, where i use it in the javascript.

Does anyone know, if so, could you please enlighten me.

Thank you,

Edward
 
THanks for that, got it working now.

Was just parent.document.blah etc

Im stuck again now though.

My javascript decides not to work when i try to pass a peice of code as text through it.

Here's my code that im using.

PHP:
echo "<a href=javascript:addtext('<img src=edward.jpg>');>file</a><br/>";

It works fine when i put in
PHP:
echo "<a href=javascript:addtext('edward');>file</a><br/>";

So im guessing its to do with the text formatting that i am using.

Im wanting to put in the addtext parameter a peice of code like <img src="edward.jpg" size="200" class="imgFrame"/>

How do i need to set it out to do that? I think its finding a speech mark or something somewhere that is cutting the javascript apart.

When i use that top peice of code, the page displays

');?>file

and thats it. Can someone please explain where I'm going wrong?

Cheers again

Edward
 
edwardcasbon1 said:
Here's my code that im using.
PHP:
echo "<a href=javascript:addtext('<img src=edward.jpg>');>file</a><br/>";

I'm not sure exactly what going wrong but trying this might help:

Code:
echo '<a href="javascript:addtext(\'<img src=edward.jpg />\')">file</a><br/>';

If that doesn't work I guess you could create an addimage function, which takes the src as an argument and adds in the HTML itself.
 
Back
Top Bottom